Use Forced Decisions for QA and Testing
Why force decisions during QA
Section titled “Why force decisions during QA”Normal bucketing is deterministic but opaque — you cannot predict which variation a given user ID receives. During QA, you need to see every variation on demand to verify rendering, behavior, and analytics. Forced decisions override the bucketing algorithm for specific users without affecting production traffic.
What you will do
Section titled “What you will do”- Identify the flag key and variation key to force
- Apply the forced decision using the appropriate method
- Verify the forced variation is served
- Remove forced decisions before production
Feature Experimentation: force decisions in code
Section titled “Feature Experimentation: force decisions in code”Step 1: Set a forced decision
Section titled “Step 1: Set a forced decision”Use setForcedDecision on the user context to override bucketing for a specific flag and optional rule (experiment or delivery).
const user = optimizely.createUserContext('qa-tester-1');
// Force the 'checkout_flow' flag to serve 'variation_b'
user.setForcedDecision(
{ flagKey: 'checkout_flow' },
{ variationKey: 'variation_b' }
);
const decision = user.decide('checkout_flow');
console.log(decision.variationKey); // 'variation_b' user = client.create_user_context('qa-tester-1')
# Force the 'checkout_flow' flag to serve 'variation_b'
user.set_forced_decision(
OptimizelyDecisionContext('checkout_flow'),
OptimizelyForcedDecision('variation_b')
)
decision = user.decide('checkout_flow')
print(decision.variation_key) # 'variation_b' var user = optimizely.CreateUserContext("qa-tester-1");
// Force the 'checkout_flow' flag to serve 'variation_b'
user.SetForcedDecision(
new OptimizelyDecisionContext("checkout_flow"),
new OptimizelyForcedDecision("variation_b")
);
var decision = user.Decide("checkout_flow");
Console.WriteLine(decision.VariationKey); // 'variation_b' Step 2: Force a decision for a specific rule
Section titled “Step 2: Force a decision for a specific rule”When a flag has multiple rules (experiments and deliveries), target a specific rule by including the rule key.
// Force only within a specific experiment rule
user.setForcedDecision(
{ flagKey: 'checkout_flow', ruleKey: 'checkout_experiment_q1' },
{ variationKey: 'variation_a' }
); # Force only within a specific experiment rule
user.set_forced_decision(
OptimizelyDecisionContext('checkout_flow', 'checkout_experiment_q1'),
OptimizelyForcedDecision('variation_a')
) // Force only within a specific experiment rule
user.SetForcedDecision(
new OptimizelyDecisionContext("checkout_flow", "checkout_experiment_q1"),
new OptimizelyForcedDecision("variation_a")
); Step 3: Remove forced decisions
Section titled “Step 3: Remove forced decisions”// Remove a specific forced decision
user.removeForcedDecision({ flagKey: 'checkout_flow' });
// Remove all forced decisions for this user
user.removeAllForcedDecisions(); # Remove a specific forced decision
user.remove_forced_decision(
OptimizelyDecisionContext('checkout_flow')
)
# Remove all forced decisions for this user
user.remove_all_forced_decisions() // Remove a specific forced decision
user.RemoveForcedDecision(
new OptimizelyDecisionContext("checkout_flow")
);
// Remove all forced decisions for this user
user.RemoveAllForcedDecisions(); Web Experimentation: force variations in the UI
Section titled “Web Experimentation: force variations in the UI”Option 1: Force via URL parameters
Section titled “Option 1: Force via URL parameters”Append optimizely_x parameters to your page URL:
https://yoursite.com/checkout?optimizely_x1234567890=1
The format is optimizely_x{experiment_id}={variation_index} where 0 is the original and 1, 2, etc. are treatment variations.
Option 2: Force via the Optimizely extension
Section titled “Option 2: Force via the Optimizely extension”- Install the Optimizely browser extension
- Navigate to your page
- Open the extension and select the experiment
- Choose the variation to preview
- The page reloads with the forced variation applied
Option 3: Force via the Optimizely application
Section titled “Option 3: Force via the Optimizely application”- Open the experiment in the Optimizely application
- Click Preview on a specific variation
- A shareable QA link is generated that forces that variation
Verification checklist
Section titled “Verification checklist”After forcing a decision, confirm:
- The correct variation renders visually
- Feature variables return expected values
- Conversion events fire when you complete the target action
- Analytics payloads include the correct variation key
- Removing the forced decision returns normal bucketing behavior
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| Forced decision ignored | Wrong flag key or variation key | Copy keys directly from the Optimizely application |
| Force works but events missing | QA user not tracked | Ensure trackEvent is called after the forced decision |
| URL parameter not working | Experiment paused or snippet missing | Verify the experiment is running and the snippet is on the page |
| Force persists after removal | Browser cache or sticky bucketing | Clear cookies and local storage, then reload |