# Experiment (/experiment)



Don't guess. Test. headless.ly connects experimentation directly to revenue -- because Experiments, FeatureFlags, Funnels, and Stripe billing all live in the same graph.

```typescript
import { Experiment, FeatureFlag } from '@headlessly/experiments'

// A/B test pricing with real Stripe revenue as the metric
await Experiment.create({
  name: 'Pricing v2',
  type: 'ABTest',
  variants: ['$29', '$49'],
  metric: 'mrr',
})

// Progressive feature rollout
await FeatureFlag.create({ key: 'new-onboarding', rollout: 25 })
await FeatureFlag.rollout({ key: 'new-onboarding', percentage: 50 })
await FeatureFlag.rollout({ key: 'new-onboarding', percentage: 100 })
```

Key Entities [#key-entities]

| Entity          | Purpose                                       | Key Verbs                |
| --------------- | --------------------------------------------- | ------------------------ |
| **Experiment**  | A/B tests on pricing, onboarding, features    | start, stop, declare     |
| **FeatureFlag** | Progressive rollouts, beta access             | enable, disable, rollout |
| **Funnel**      | Conversion flows -- signup to activate to pay | analyze, compare         |

Real Revenue as the Metric [#real-revenue-as-the-metric]

Most experimentation tools measure clicks and pageviews. headless.ly measures actual Stripe revenue:

```typescript
import { Experiment } from '@headlessly/experiments'

// Analyze the pricing experiment
const result = await Experiment.analyze({ id: 'exp_qR7wNxBt' })
// {
//   variants: [
//     { name: '$29', conversions: 45, mrr_impact: 1305 },
//     { name: '$49', conversions: 31, mrr_impact: 1519 },
//   ],
//   winner: '$49',
//   confidence: 0.94,
// }

// Declare the winner
await Experiment.declare({ id: 'exp_qR7wNxBt', winner: '$49' })
```

Funnel Analysis [#funnel-analysis]

Track the full revenue pipeline:

```typescript
import { Funnel } from '@headlessly/analytics'

await Funnel.analyze({ id: 'funnel_pK3xMwDv' })
// visitor -> signup -> activated -> trial -> paid
// 10,000 -> 890 -> 340 -> 120 -> 45
// Conversion: 0.45%
```

Events come from the browser SDK (forwarded to PostHog + stored in lakehouse). Revenue comes from Stripe. The funnel connects both.
