HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

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.

Version

SDK v1.0 and higher

Description

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.

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.

Returns

(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

Example

Creating a client with Forced Variation service:

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

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.


Did this page help you?