# Experiments

Run an A/B test on a feature flag's variants, read results you can check any time, and end it with a recorded decision.

An experiment reads a [feature flag](/feature-flags)'s variants as an A/B test.
It measures what each variant changes in the events you already send, and shows
the result with an interval you can trust at any point, not only at the end.

Experiments live under **Data > Experiments**, and on the **Experiments** tab of
each flag.

## What you need

- A flag with two or more variants, or a boolean flag (its variants are `false`
  and `true`, and the control is `false`).
- Your app calling the flag through a Cohorly SDK, so each user's exposure is
  recorded as a `$feature_flag_called` event.
- The events you want to measure, already flowing into the project.

### Without a Cohorly flag

If you assign variants with another flag tool or on your server, you can still
analyze the test in Cohorly. Create the experiment without a flag and tell it:

- the **exposure event**: any event you send when a user is assigned, with
  optional property filters;
- the **variant property**: the event property that holds the variant name;
- the **variants**, control first, and optionally the share each should get, so
  the sample ratio check can compare.

Cohorly never changes anything served to your users in this case: starting,
pausing and ending only record when the experiment ran, and the decision is
yours to apply in your own tool.

## Create an experiment

1. Open **Data > Experiments** and choose **New experiment**. Choose what
   exposes a user: **A Cohorly flag** (then pick the flag) or **A custom
   exposure event** (see [Without a Cohorly flag](#without-a-cohorly-flag)).
   From a flag, open its **Experiments** tab instead.
2. Give it a **name** and, optionally, a **hypothesis**.
3. Pick the **control**: the variant every lift is compared against.
4. Add **metrics** (see below).
5. Optionally add **population filters** to count only users whose events match
   a property.
6. Choose the **confidence** (90%, 95% or 99%) and how to treat **users who see
   more than one variant**: exclude them (the default) or keep them in the first
   variant they saw.
7. Optionally adjust **variance reduction (CUPED)**, on by default with a 14-day
   look-back, and the **correction across metrics**, Holm by default (see
   [How the statistics work](#how-the-statistics-work)).
8. Use the **sample-size calculator** to set the planned sample, then save the
   draft.

A draft changes nothing about your flag. You can edit or delete it freely.

## Metrics and directions

Every experiment has **one to three primary metrics**, up to **4 secondary
metrics** and up to **5 guardrails**, nine metrics in total.

| Role      | Use it for                                                    |
| --------- | ------------------------------------------------------------- |
| Primary   | The one outcome the decision rests on.                        |
| Secondary | Other outcomes you want to see move.                          |
| Guardrail | Something that must not get worse, such as errors or refunds. |

Each metric is an event plus a measure:

| Measure                  | What it counts for each exposed user                    |
| ------------------------ | ------------------------------------------------------- |
| Conversion               | 1 if the user did the event at least once, otherwise 0. |
| Count per user           | How many times the user did the event.                  |
| Sum of property per user | The sum of a numeric property over the user's events.   |

Each metric also has a direction, **higher is better** or **lower is better**,
which decides whether a change is good or bad. Guardrails usually say lower is
better.

A guardrail can also have a **tolerance**, in percent: how much it may worsen
against the control before the results stop recommending to ship a variant.
With a 2% tolerance on errors (lower is better), a variant whose errors rise
more than 2% is not recommended, and the results name the guardrail. Without a
tolerance a guardrail never blocks the recommendation. It is advice: you can
still end the experiment with any decision.

Only events from a user's first exposure onward count. A user who is exposed and
never does the event counts as 0 and stays in the sample.

### Retention metrics

A conversion metric can count only a **window after exposure**, for example
"came back between day 7 and day 14". Only users whose whole window has passed
are counted, so a user exposed yesterday does not drag a 14-day retention down.

### Ratio metrics

A ratio metric divides one event measure by another, per variant, for example
revenue per order or errors per session. Pick a numerator and a denominator,
each an event with its measure and filters. Its interval accounts for both
parts varying together. A ratio can also be an experiment's only metric.

### Outliers

A count or sum metric is **capped at the 99th percentile** of exposed users by
default, so one user with a thousand purchases cannot decide the result. The
cap is the same for every variant, and the results show it and how many users
were capped. You can choose another percentile, from 90 to 99.99, or turn
capping off for that metric.

## Lifecycle

| Status    | Meaning                                                |
| --------- | ------------------------------------------------------ |
| Draft     | Being set up. Editable. No results yet.                |
| Running   | Counting exposures. The flag is on.                    |
| Paused    | The flag is off for everyone. Resume turns it back on. |
| Concluded | Ended with a recorded decision. It never reopens.      |

- **Start** turns the flag on if it was off, and locks the split (see below).
- **Pause** turns the flag off for everyone until you resume.
- **End experiment** stops it for good and asks for your decision.

A flag can have one running or paused experiment at a time.

### The split is locked while it runs

While an experiment is running or paused, you cannot change the flag's variant
keys, their order, a variant's rollout percentage, or a strategy's pinned
variant. Everything else stays free: strategies, the Enabled switch and the
Override. The API answers a refused change with `409 experiment_running`.
Archiving or deleting the flag is refused the same way until the experiment
ends.

Changes you do make are listed as **Config changed during the test** on the
results screen, so a reader can see them.

## Read the results

The results screen shows, top to bottom: the header and its one action, the
health checks, the exposures, the metrics and, once ended, the conclusion.

Every result is **per user**, relative to the control, and states its method:
"Sequential, 95% confidence, safe to check any time" (with your level).

### Metrics table

One row per metric and non-control variant shows the control value, the variant
value, the relative **lift**, and an **interval** drawn around a 0% line.

The color is a verdict, and always comes with its word:

- **Better** (green): the interval excludes 0 on the good side of the metric.
- **Worse** (red): the interval excludes 0 on the bad side.
- **Inconclusive** (grey): the interval includes 0, or there is not enough data
  yet.

Each metric names what was applied to it: **CUPED** when variance reduction
was used, "N users capped at p99" when outliers were capped, and
**Exploratory** on secondary metrics. **Method**, next to the metric, shows
the confidence and the alpha its interval is drawn at, after the correction
across metrics.

**Minimum detectable effect** is the smallest lift the current sample can tell
apart from 0, at the same confidence as the interval, for example "±6.3%". It
shrinks as more users are exposed, and shows "-" until there is enough data.

Every table shows the **period** its numbers cover, from the first to the last
day of the analysis.

### Ship recommendation

For each variant, the results say whether shipping it is recommended: every
primary metric reads **Better** and no guardrail worsened beyond its tolerance.
When a guardrail blocks it, a warning names that guardrail. The
recommendation never stops you from ending the experiment.

Turn on **Chance to beat control** to add a column with a plain-language
reading of the same lift. It is off by default and never changes the verdict:
only the interval does.

**Open in Explore** opens the experiment's own query in Explore, read-only:
one row per variant with its exposed users and the average per user of every
metric, the metric you came from highlighted. The highlighted number is the
one on the results row. **Explore by variant over time** opens an ordinary
trend you can edit: the metric itself, one line per variant, each counting
only users exposed to that variant at least once in the chart's window. It is
not anchored on each user's first exposure the way the results are, and its
window is the chart's date range, not the experiment's, so its numbers can
differ from the results row. Both are ways to dig deeper, not a different
result.

### Variance reduction (CUPED)

With CUPED on, Cohorly also reads what each user did on the same metric in the
look-back before their first exposure, and removes the part of the difference
that this history already explains. The interval gets narrower, usually by a
lot for metrics that repeat, such as purchases or sessions, without moving the
lift on average. The results show how much the variance went down. CUPED does
not apply to ratio metrics.

### Difference over time

**Show difference over time** on a metric draws each variant's cumulative lift
against the control, day by day. Use it to see whether an effect is stable or
fading. This view
uses the raw values, without variance reduction or outlier capping, so it can
differ slightly from the metric's lift. Ratio and retention metrics do not
have it.

### Segments and filters

Under **Break down by** you can split the results by a property, read from the
exposure event or from the profile, such as country or plan (the top
10 values, the rest grouped as "Other", listed last and kept apart from a real
value named "Other"), or apply filters after the start. The
segments use the same metrics and layout. They are exploratory: the overall
result and its verdicts never change, and a segment with a striking result is a
hypothesis for the next experiment, not a finding.

### Session replays per variant

Each variant links to the session replays with an exposure to that variant
during the experiment. It is a shortcut to sessions, not the variant's exact
analysed users: it covers whole days and ignores pauses.

### Holdout

If the flag belongs to a [holdout](/feature-flags), the results add a readout
of the held-out users against each variant, one line per variant: the
cumulative impact of that variant. The control is left out, because like the
holdout it is the flag off, so mixing it in would shrink the impact. Once you
ship a variant, its line comes first. The readout is never part of the variant
comparison or the sample ratio check.

### Not enough data yet

Until each variant in a comparison has at least **100 exposed users**, the
experiment says "Collecting data: N of 100" and its rows are grey Inconclusive
with the reason. A conversion metric also needs at least **25 conversions** in
each variant, a count or sum metric needs a control average that is clearly
above zero, and no verdict is shown in the first **24 hours**. This is a normal
state, not an error.

## Health checks

| Check                          | What it tells you                                                                                                                                                                                                                                                                                                                                                         |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Sample ratio                   | Whether the users in each variant match the split you configured. A mismatch (p < 0.001) is red: results are not trustworthy until you explain it, and metric verdicts are greyed out. The p-value is always shown. On a flag with an Override or a pinned strategy the split is not purely random, so the check is marked **less reliable** and never greys out results. |
| Multiple-variant users         | How many users saw more than one variant, and the policy applied. A share above 1% shows a warning.                                                                                                                                                                                                                                                                       |
| Minimum data                   | Whether the minimums above are reached.                                                                                                                                                                                                                                                                                                                                   |
| Config changed during the test | Changes to the flag's variants, strategies or Enabled state made while the experiment ran, with when and who. Not applicable without a Cohorly flag.                                                                                                                                                                                                                      |
| Pre-experiment bias            | Whether the variants already differed on the primary metric before exposure, from the CUPED look-back. A difference is a warning: check how users are assigned. It never greys out results. Not applicable with CUPED off.                                                                                                                                                |

Next to the checks, **progress** shows "about N days left" against your planned
sample, or "Target reached".

## How the statistics work

Cohorly uses a **sequential** method. In plain language:

- **Safe to check any time.** A classic test is only valid if you look once, at
  a planned sample size. Looking early and stopping when it looks good inflates
  false positives. A sequential interval stays valid however often you look, so
  you can open the screen every day.
- **The interval narrows as data arrives.** It is an interval for the relative
  lift. When it excludes 0, the verdict turns green or red.
- **Several variants are corrected.** With more than two variants, each is
  compared with the control at a stricter level (Bonferroni: your significance
  level divided by the number of comparisons), so having more variants does not
  make false positives more likely.
- **Several metrics are corrected too.** The primary metrics and the guardrails
  are corrected together, with Holm (the default) or Bonferroni, so checking
  three primaries does not triple the false positives. Each metric shows the
  level it was tested at. Secondary metrics are marked exploratory and are not
  part of the correction.
- **The planned sample sets how fast it narrows.** It is locked once the
  experiment starts, together with the confidence level.
- **The cost.** A sequential test needs about **1.9 times** the sample of a
  fixed-horizon test planned for the same effect. That is the price of checking
  any time.

The p-value shown is the one that matches the interval: the smallest
significance level at which the interval would exclude 0. Like the interval, it
stays valid however often you look.

## Plan the sample size

The calculator in the form works out how many users you need.

1. **Baseline.** For a conversion metric it is pre-filled from the last 30 days
   (users who did the event over users who did anything) and you can edit it.
   For a count or sum metric, type the typical value per user and its spread.
2. **Smallest change to detect.** A relative change, such as 5%.
3. Optionally, **exposed users per day**, to turn the sample into days.

It shows the users needed for the control and one variant, the total across all
variants, and the days when you gave a daily rate. Choose **Use this sample** to
plan the experiment with it. If you skip the calculator, a default of 5,000
users per comparison is used.

## End the experiment and ship

Choose **End experiment** on a running or paused experiment. Pick one:

- **Ship a variant**, then which one.
- **Roll back to the control.**
- **End as inconclusive.**

A **note** is required, so anyone reading the flag's Activity understands why.
The decision, the note, who made it and when are stored and shown above the
metrics.

Ending never changes your flag silently. Shipping offers **Serve X to everyone
the flag reaches** and rolling back offers **Serve the control to everyone the
flag reaches**, both on by default. When on, the flag is edited right after the
decision and recorded as its own entry in the flag's Activity. When off, the
flag is left exactly as it was. If the sample ratio check failed, you confirm
once more before ending.

An experiment without a Cohorly flag never edits a flag: apply the decision in
your own tool.

## Exposed users per month

Your plan includes a number of **users exposed to experiments each month**,
counted from each user's first exposure, per experiment. Only users counted in
the experiment's results count: when users seen in more than one variant are excluded,
those users count neither in the results nor here. Going over it never
stops an experiment or hides a result: experiments keep collecting, and the
results screen shows a notice. The `$feature_flag_called` exposure events do not
count against your monthly event quota, and are stored even when that quota is
reached.

## Experiments over the API and MCP

Experiments are available through the HTTP API and to AI agents through MCP. Starting, pausing, resuming and ending an experiment change what users
see or record a decision, so MCP asks for approval first.
