Feature flags & experiments
Roll out features gradually and A/B test them with built-in statistics.
Create a flag
Under Feature Flags → New flag, choose a key (e.g. new-checkout), a rollout percentage, and optionally variants with weights (e.g. control: 50, test: 50). Targeting conditions can limit a flag by country, device, page path, browser, OS or language.
Evaluate in the browser
const enabled = await stancelens.flag("new-checkout");
if (enabled) showNewCheckout();
// Multivariate flags resolve to the variant key
const variant = await stancelens.flag("pricing-copy"); // "control" | "test" | falseEvaluation is deterministic per ID. An identified user gets the same answer on every device. Anonymous web visitors are bucketed by the daily visitor hash, so their answer can change from one day to the next; mobile SDKs send a persistent install ID instead. The tracker loads its flags module on the first stancelens.flag() call and fetches all flags once per page load and user ID, with the page path for targeting. The first time a flag resolves on a page load it sends an $exposure event with { flag, variant }, also when the value is false, so visitors who get the control experience are counted in experiments. A key the server doesn't know records nothing.
React example
function useFlag(key: string) {
const [value, setValue] = useState<boolean | string>(false);
useEffect(() => {
stancelens.flag(key).then(setValue);
}, [key]);
return value;
}
function Checkout() {
const variant = useFlag("new-checkout");
return variant ? <NewCheckout /> : <OldCheckout />;
}Experiments
An experiment ties a flag to a goal. Under Experiments → New experiment, pick the flag and the goal event. Exposures come from the $exposure events above; the report shows conversion rate per variant, uplift against control with a confidence interval, and the probability each variant is best.
- Wait until each variant has at least a few hundred exposures before calling a winner.
- Don't change weights mid-experiment. Create a new experiment instead.
- Ship the winner by setting its weight to 100%, then remove the flag from code.