Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

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 doesn't persist across application launches.


SDK v1.0.0 and higher


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.


This table lists the required parameters for the Go SDK.

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.
stringThe key of the forced variation.


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

overrideStore := decision.NewMapExperimentOverridesStore()
client, err := optimizelyFactory.Client(
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.