# Feature flags and A/B tests on Cloudflare Workers

Dataflare evaluates feature flags in your Worker and reports experiments on the same events as your analytics, so there's no second tool to wire up.

## A flag

```js
if (glass.flag('new-checkout')) showNewCheckout();
```

Flags have a rollout percentage and targeting rules on any event or person property (for example, `person.plan` is `pro`). Assignment is deterministic per person, so people see the same thing on every visit.

## An experiment

1. Create it with a goal event, in the dashboard or with your agent (`create_experiment`). It creates a flag with `control` and `test` variants.
2. Branch on the variant where it's shown, so exposure is recorded at the right moment:

   ```js
   const variant = glass.flag('pricing-page-v2'); // "control" or "test"
   ```
3. Start it. Results show exposures, conversion per variant, a 95% interval, the probability that each variant beats control, and the lift.
4. Ship the winner: the flag then serves that variant to everyone.

## How results are computed

Each person enters the experiment at their first exposure, and counts as converted if they do the goal event afterwards. People exposed to more than one variant are left out and counted separately. Dataflare checks for sample-ratio mismatch, which usually means the exposure is logged in the wrong place. The details are in [Flags and experiments](/docs/experiments/).
