Skip to content

Use Forced Decisions for QA and Testing

⏱ 10 minutes beginner

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.

  1. Identify the flag key and variation key to force
  2. Apply the forced decision using the appropriate method
  3. Verify the forced variation is served
  4. Remove forced decisions before production

Feature Experimentation: force decisions in code

Section titled “Feature Experimentation: force decisions in code”

Use setForcedDecision on the user context to override bucketing for a specific flag and optional rule (experiment or delivery).

Force a specific variation
javascript
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'
python
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'
csharp
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 a decision for a specific experiment rule
javascript
// Force only within a specific experiment rule
user.setForcedDecision(
  { flagKey: 'checkout_flow', ruleKey: 'checkout_experiment_q1' },
  { variationKey: 'variation_a' }
);
python
# Force only within a specific experiment rule
user.set_forced_decision(
    OptimizelyDecisionContext('checkout_flow', 'checkout_experiment_q1'),
    OptimizelyForcedDecision('variation_a')
)
csharp
// Force only within a specific experiment rule
user.SetForcedDecision(
    new OptimizelyDecisionContext("checkout_flow", "checkout_experiment_q1"),
    new OptimizelyForcedDecision("variation_a")
);
Remove forced decisions
javascript
// Remove a specific forced decision
user.removeForcedDecision({ flagKey: 'checkout_flow' });

// Remove all forced decisions for this user
user.removeAllForcedDecisions();
python
# Remove a specific forced decision
user.remove_forced_decision(
    OptimizelyDecisionContext('checkout_flow')
)

# Remove all forced decisions for this user
user.remove_all_forced_decisions()
csharp
// 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”

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”
  1. Install the Optimizely browser extension
  2. Navigate to your page
  3. Open the extension and select the experiment
  4. Choose the variation to preview
  5. The page reloads with the forced variation applied

Option 3: Force via the Optimizely application

Section titled “Option 3: Force via the Optimizely application”
  1. Open the experiment in the Optimizely application
  2. Click Preview on a specific variation
  3. A shareable QA link is generated that forces that variation

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
IssueCauseFix
Forced decision ignoredWrong flag key or variation keyCopy keys directly from the Optimizely application
Force works but events missingQA user not trackedEnsure trackEvent is called after the forced decision
URL parameter not workingExperiment paused or snippet missingVerify the experiment is running and the snippet is on the page
Force persists after removalBrowser cache or sticky bucketingClear cookies and local storage, then reload