Dev guideAPI Reference
Dev guideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Set Forced Variation

This topic describes the Set Forced Variation method, which forces a user into a variation for a given experiment for the lifetime of the Optimizely client.

The purpose of this method is to force a user into a specific variation for a given experiment. The forced variation value does not 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 the Decide methods or Track Event method 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. Decision 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.

ParameterTypeDescription
overrideKey
All keys inside object are also required
ExperimentOverrideKeyExperimentOverrideKey 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
stringThe 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.