Create an Experiment
Creating an A/B Experiment in GrowthBook
Section titled “Creating an A/B Experiment in GrowthBook”GrowthBook lets you run experiments either as standalone Experiments or as Experiment rules attached to a Feature flag. Both paths converge on the same experiment editor — the steps below cover the most common path: adding an Experiment rule to an existing feature flag.
Step 1 — Open the Features list and choose a feature
Section titled “Step 1 — Open the Features list and choose a feature”- Log in to GrowthBook at
http://localhost:3000(or your Cloud URL). - In the left sidebar, click Features.
- Click the feature you want to experiment on — for example,
checkout-experiment.
Step 2 — Add an Experiment rule
Section titled “Step 2 — Add an Experiment rule”- On the Feature detail page, locate the environment where you want to run the test (e.g. production).
- Click Add Rule and select Experiment from the rule-type dropdown.
- The experiment editor opens inline.
Step 3 — Define your variations
Section titled “Step 3 — Define your variations”- Under Variations, you will see a Control row already present.
- Click Add Variation to create one or more treatment variants.
- Set the Value for each variation. For a string feature this is the value the SDK returns — e.g.
'control'and'variant'. - Give each variation a human-readable Name so reports are readable.
Step 4 — Set the traffic split
Section titled “Step 4 — Set the traffic split”- In the Traffic section, set the percentage of users included in the experiment (e.g.
50%to expose half your traffic). - Adjust the weights between variations. Equal weights (
50 / 50) are the default and recommended starting point. - GrowthBook uses a deterministic hash of the user ID to assign buckets — the same user always sees the same variation.
Step 5 — Choose your metrics
Section titled “Step 5 — Choose your metrics”- Scroll to the Metrics section.
- Click Add Metric and search for your primary metric (e.g.
checkout_completed). - Add any secondary or guardrail metrics you want to monitor.
- Mark exactly one metric as the Primary metric — this is the single source of truth for your decision.
Step 6 — Start the experiment
Section titled “Step 6 — Start the experiment”- Review the Hypothesis field and type a falsifiable statement, e.g. “Showing the new checkout flow will increase checkout_completed by 5%.”
- Click Save Rule, then toggle the environment from Draft to Running.
- GrowthBook begins collecting impression and conversion data immediately.
Checking the variation in your code
Section titled “Checking the variation in your code”After the experiment is live, use getFeatureValue to read the assigned variation. Branch your logic on the returned string:
import { GrowthBook } from '@growthbook/growthbook';
const gb = new GrowthBook({
apiHost: 'https://cdn.growthbook.io',
clientKey: 'sdk-YOUR_DEV_KEY',
trackingCallback: (experiment, result) => {
// Send impression to your analytics pipeline
console.log('Experiment:', experiment.key, 'Variation:', result.variationId);
},
});
await gb.init({ timeout: 2000 });
const variation = gb.getFeatureValue('checkout-experiment', 'control');
if (variation === 'variant') {
// Show the new checkout flow
renderNewCheckout();
} else {
// Default: show the original checkout flow
renderOriginalCheckout();
}