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

Get Forced Variation

This topic describes the Get Forced Variation method, which returns the forced variation set by Set Forced Variation, or null if no variation was forced.

A user can be forced into a variation for a given experiment for the lifetime of the Optimizely client. This method gets the variation that the user has been forced into. The forced variation value is runtime only and does not persist across application launches.

Returns (string, bool), representing the current forced variation for the argument experiment key and user ID. If no variation was previously set, returns "", false. Otherwise, returns the previously set variation key as the first return value, and true as the second return value.


SDK v1.0 and higher


Forced bucketing variations take precedence over whitelisted variations, variations saved in a User Profile Service (if one exists), and the normal bucketed variation. Variations are overwritten when Set Variation is invoked.


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.


(string, bool)

  • The key of the currently set forced variation for the argument user and experiment, or an empty string if no forced variation is currently set
  • true if a forced variation is currently set for the argument user and experiment, false otherwise


Creating a client with Forced Variation service:

overrideStore := decision.NewMapExperimentOverridesStore()
client, err := optimizelyFactory.Client(

Using Forced Variation service Get Variation:

overrideKey := decision.ExperimentOverrideKey{ExperimentKey: "test_experiment", UserID: "test_user"}
variation, success := overrideStore.GetVariation(overrideKey)

See also

Set Variation
Remove Variation

Source files

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