GuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

Set Forced Variation

The purpose of this method is to force a user into a specific variation for a given experiment. The forced variation value doesn't persist across application launches.

Version

SDK v1.0.0 and higher

Description

Forces a user into a variation for a given experiment for the lifetime of the Optimizely client. Any future calls to Activate, Is Feature Enabled, Get Feature Variable, and Track for the given user ID returns the forced variation.

Forced bucketing variations take precedence over whitelisted variations, variations saved in a User Profile Service (if one exists), and the normal bucketed variation. Impression and conversion events are still tracked when forced bucketing is enabled.

Variations are overwritten with each set method call. To clear the forced variations so that the normal bucketing flow can occur, use Remove Variation method of passed ExperimentOverridesStore service. To get the variation that has been forced, use Get Variation method of passed ExperimentOverridesStore service.

Parameters

This table lists the required parameters for the Go SDK.

Parameter

Type

Description

overrideKey
All keys inside object are also required

ExperimentOverrideKey

ExperimentOverrideKey contains,

  • ExperimentKey (string): The key of the experiment to set with the forced variation.
  • UserID (string): The ID of the user to force into the variation.

variationKey
required

string

The key of the forced variation.

Example

Creating client with Forced variation service and then setting forced variation:

overrideStore := decision.NewMapExperimentOverridesStore()
client, err := optimizelyFactory.Client(
       client.WithExperimentOverrides(overrideStore),
   )
overrideKey := decision.ExperimentOverrideKey{ExperimentKey: "test_experiment", UserID: "test_user"}
overrideStore.SetVariation(overrideKey, "test_variation")

See also

Get Variation
Remove Variation

Source files

The language/platform source files containing the implementation for Go is client.go.


Did this page help you?