Feature Flags
Feature flags let you enable or disable functionality for segments of visitors without deploying new code for every change.
What are feature flags?
Section titled “What are feature flags?”A feature flag is an experiment of type feature_flag. Visitors are assigned to a variant, and your application code reads the assignment to decide which code path to run.
Ttoolab handles assignment, exposure tracking, and reporting. Your code handles the feature logic.
When to use feature flags
Section titled “When to use feature flags”Use feature flags for:
- Gradual rollouts of new features
- Kill switches for risky changes
- Internal or beta access for a subset of traffic
- Long-lived toggles that may not have a clear end date
Feature flag vs A/B test
Section titled “Feature flag vs A/B test”| | Feature flag | A/B test |
| :- | :----------- | :------- |
| Purpose | Control feature availability | Compare variant performance |
| Duration | Often long-running | Usually time-bound |
| Implementation | Code checks getVariant() | DOM changes or URL routing |
| Webhook events | feature_flag.created, feature_flag.updated, feature_flag.exposed | experiment.* events |
Both use the same assignment engine under the hood.
How to create a feature flag
Section titled “How to create a feature flag”- Create a new experiment and select type Feature flag.
- Set URL rules and traffic allocation.
- Create variants (e.g.
offas control,onas treatment). - Publish the experiment.
Read the flag in your code
Section titled “Read the flag in your code”window.ttoolab?.ready(() => { const variant = window.ttoolab?.getVariant("new-checkout-flag");
if (variant === "on") { enableNewCheckout(); } else { enableLegacyCheckout(); }});Always wrap flag checks in ttoolab.ready() to ensure assignments are loaded.
Webhook events
Section titled “Webhook events”When feature flags are created, updated, or exposed, Ttoolab can send:
feature_flag.createdfeature_flag.updatedfeature_flag.exposed
Configure these in your project’s webhook settings.
Cautions when publishing changes
Section titled “Cautions when publishing changes”- Code and flag must agree — if your code checks
variant === "on"but the dashboard variant key isenabled, the flag will not work. - Default to safe — when the pixel fails to load, default to the conservative code path (usually control/off).
- Avoid nested flags — too many interacting flags make behavior hard to predict.
- Clean up old flags — remove flag checks from code when a flag is fully rolled out.
- Do not change variant keys after launch without updating application code.