Create an Experiment
Why create an experiment
Section titled “Why create an experiment”Shipping changes without measurement is guessing. An experiment lets you compare variations of a page, feature, or flow against a control, using real user behavior as the judge. By structuring changes as experiments, you get statistical proof of what works before committing to a permanent rollout.
What you will do
Section titled “What you will do”- Define a hypothesis and choose an experiment type
- Create the experiment in the Optimizely application
- Add variations
- Set traffic allocation
- Start the experiment
Choose an experiment type
Section titled “Choose an experiment type”| Type | Best for | How variations are delivered |
|---|---|---|
| A/B test (Web) | Visual changes — headlines, layouts, CTAs | Optimizely snippet modifies the page in the browser |
| Feature experiment | Backend logic, algorithms, pricing | Your application code reads flag values via an SDK |
| Multi-armed bandit | Quickly converging on a winner | Optimizely dynamically shifts traffic toward the best variation |
Create an A/B test (Web Experimentation)
Section titled “Create an A/B test (Web Experimentation)”- In the Optimizely application, navigate to Experiments and click Create New Experiment
- Select A/B Test
- Enter the experiment name — use a clear, descriptive name like “Homepage hero CTA test Q1 2026”
- Set the URL targeting — enter the page URL where the experiment runs
- Click Create Experiment
Add variations
Section titled “Add variations”- In the experiment editor, click Create Variation
- Name the variation (e.g., “Green CTA button”)
- Use the visual editor to modify elements on the page — click any element to change text, styles, or layout
- For advanced changes, switch to code mode and add custom JavaScript or CSS
- Repeat for additional variations
Set traffic allocation
Section titled “Set traffic allocation”- Navigate to the Traffic Allocation section
- Set the percentage of visitors included in the experiment (start with 100% for most tests)
- Distribute traffic evenly across variations or set custom splits
- The Original (control) always receives its share of traffic
Create a feature experiment (Feature Experimentation)
Section titled “Create a feature experiment (Feature Experimentation)”- Navigate to Feature Flags and create or select a flag
- Add variables to the flag for each value you want to test (e.g.,
button_color,algorithm_version) - Navigate to Experiments and click Create New Experiment
- Select Feature Experiment
- Choose the flag you created
- Add variations and set different variable values for each
Implement the flag in code
Section titled “Implement the flag in code”Your application reads the flag decision at runtime. The SDK handles variation assignment and bucketing.
import { createInstance } from '@optimizely/optimizely-sdk';
const optimizely = createInstance({
sdkKey: 'YOUR_SDK_KEY',
});
await optimizely.onReady();
const user = optimizely.createUserContext('user-123', {
country: 'US',
plan: 'premium',
});
const decision = user.decide('checkout_flow');
if (decision.enabled) {
const buttonColor = decision.variables.button_color;
const algorithm = decision.variables.algorithm_version;
renderCheckout({ buttonColor, algorithm });
} else {
renderCheckout({ buttonColor: 'blue', algorithm: 'v1' });
} from optimizely import optimizely
client = optimizely.Optimizely(sdk_key='YOUR_SDK_KEY')
user = client.create_user_context('user-123', {
'country': 'US',
'plan': 'premium',
})
decision = user.decide('checkout_flow')
if decision.enabled:
button_color = decision.variables['button_color']
algorithm = decision.variables['algorithm_version']
render_checkout(button_color, algorithm)
else:
render_checkout('blue', 'v1') using OptimizelySDK;
var optimizely = OptimizelyFactory.NewDefaultInstance("YOUR_SDK_KEY");
var user = optimizely.CreateUserContext("user-123", new UserAttributes
{
{ "country", "US" },
{ "plan", "premium" },
});
var decision = user.Decide("checkout_flow");
if (decision.Enabled)
{
var buttonColor = decision.Variables.GetValue<string>("button_color");
var algorithm = decision.Variables.GetValue<string>("algorithm_version");
RenderCheckout(buttonColor, algorithm);
}
else
{
RenderCheckout("blue", "v1");
} Start the experiment
Section titled “Start the experiment”Before starting, verify:
- Metrics are attached — At least one primary metric is configured (see Set Up Metrics)
- Audience is defined — Target the right users (see Configure Audiences)
- QA testing — Preview each variation to confirm it renders correctly
- Click Start Experiment
Optimizely begins assigning visitors to variations and collecting data. Results appear in the Results tab within hours, but wait for statistical significance before drawing conclusions.
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| Experiment not running | Snippet not installed or SDK not initialized | Verify installation on the target page or check SDK logs |
| Variations look identical | Visual editor changes not saved | Re-open the editor and confirm changes are saved |
| No visitors in results | URL targeting mismatch or audience too narrow | Check URL pattern matches actual page URLs |
| Uneven traffic distribution | Sticky bucketing from a previous test | Verify traffic allocation percentages and check for mutual exclusion groups |
1. You created a feature experiment, added variations with different variable values, and started the experiment. But no visitors appear in the results after 24 hours. The SDK is initialized and the feature flag exists. What is the most likely issue?
An experiment without conversion events cannot calculate lift or statistical significance. You must attach at least one primary metric before starting the experiment. Without metrics, visitor assignments may occur but no results data is recorded.
An experiment without conversion events cannot calculate lift or statistical significance. You must attach at least one primary metric before starting the experiment. Without metrics, visitor assignments may occur but no results data is recorded.
Review this topic →2. A developer needs to test two different search algorithm versions on the backend. The algorithms produce different result rankings but the UI stays the same. Which experiment approach should they use?
Backend logic changes like search algorithm versions are best tested with Feature Experimentation. You create a feature flag with a variable (e.g., algorithm_version), set different values per variation, and read the decision in your application code via the SDK.
Backend logic changes like search algorithm versions are best tested with Feature Experimentation. You create a feature flag with a variable (e.g., algorithm_version), set different values per variation, and read the decision in your application code via the SDK.
Review this topic →