Get Forced Variation

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.

Version

SDK v3.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 Forced Variation is invoked.

๐Ÿ“˜

Note

A forced variation only persists for the lifetime of an Optimizely client.

Parameters

Required and optional parameters for Android are listed below.

Parameter

Type

Description

experimentKey
required

string

The key of the experiment to retrieve the forced variation.

userId
required

string

The ID of the user in the forced variation.

Returns

The variation the user was bucketed into, or null if setForcedVariation failed to force the user into the variation.

Example

import com.optimizely.ab.config.Variation;

Variation variation = optimizelyClient.getForcedVariation(โ€œmy_experiment_keyโ€, โ€œuser_123โ€);

Source files

The language/platform source files containing the implementation for Android is OptimizelyClient.java.


Did this page help you?