Prompt
Need A/B testing with feature flags
Latest observation
Oct 13, 2026
OpenAI APIWeb search: off
A/B testing with feature flags is a common setup: use the feature flag to control which users get a variant, and use experiment tracking to measure outcomes.
Simple approach
1) Define variants
For example:
- Control = current experience
- Variant A = new button color
- Variant B = new layout
2) Assign users consistently
When a user first enters the experiment:
- assign them to a variant using a deterministic rule
- store that assignment in the flag system, cookie, user profile, or server-side cache
- keep it stable for the experiment duration
3) Gate behavior with the flag
In code:
if (featureFlags.isEnabled("new_checkout", userId)) {
renderNewCheckout();
} else {
renderOldCheckout();
}
For true A/B testing, the flag should return one of multiple variants:
const variant = featureFlags.getVariant("checkout_test", userId);
switch (variant) {
case "control":
renderOldCheckout();
break;
case "variant_a":
renderNewCheckout();
break;
}
4) Log exposure and outcomes
You need two events:
- exposure: user saw variant X
- conversion/result: user completed desired action
Example:
experiment_exposedpurchase_completed
This lets you analyze lift correctly.
5) Analyze results
Compare metrics by variant:
- conversion rate
- revenue per user
- retention
- time on page
- error rate
Important best practices
- Randomize at user level, not request level, to avoid users seeing multiple variants.
- Do not change assignments mid-experiment unless intentional.
- Track exposure before outcome to avoid bias.
- Use server-side flags for critical experiments to prevent tampering.
- Add a kill switch in case the new variant causes issues.
- Segment carefully if you want to analyze by device, region, etc.
Typical architecture
- Feature flag service: LaunchDarkly, Optimizely, Unleash, ConfigCat, homegrown
- Experiment assignment: built into flag service or separate experimentation layer
- Analytics pipeline: Segment, Snowplow, Amplitude, Mixpanel, BigQuery, etc.
Example flow
- User requests page
- Backend evaluates
checkout_test - User is assigned
controlorvariant_a - App renders assigned version
- Exposure event is logged
- User converts or drops off
- Metrics are aggregated by variant
If you want, I can also give you:
- a JavaScript/React example
- a backend implementation example
- a database schema for experiment tracking
- or a full A/B testing architecture with feature flags