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 v2.1
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.
Parameter definitions
This section provides general information about the required and optional parameters.
For the specific parameter name in one of Optimizely's supported languages, see Parameter names.
Parameter | Type | Description |
---|---|---|
experiment key required | string | The key of the experiment to retrieve the forced variation. |
user ID required | string | The ID of the user in the forced variation. |
Parameter names
This section shows the specific parameter names for each supported language.
experimentKey
userId
experimentKey
userId
experimentKey
userId
experimentKey
userId
experimentKey
userId
experimentKey
userId
$experimentKey
$userId
experiment_key
user_id
experiment_key
user_id
experimentKey
userId
Returns
The variation the user was bucketed into, or null
if Set Forced Variation failed to force the user into the variation. The example shows the return as specified for each supported language.
@return The variation the user was bucketed into, or `null` if `setForcedVariation` failed to force the user into the variation.
<returns>null|string The variation key.</returns>
@return The variation the user was bucketed into, or `null` if `setForcedVariation` failed to force the user into the variation.
@return {string|null} The variation the user was bucketed into, or `null` if `setForcedVariation` failed to force the user into the variation.
<returns>null|string The variation key.</returns>
@return The variation the user was bucketed into, or `nil` if `setForcedVariation` failed to force the user into the variation.
@return string|null The forced variation key.
Returns:
The forced variation key. None if no forced variation key.
@return [String] The variation the user was bucketed into, or `nil` if `setForcedVariation` failed to force the user into the variation.
@return forced variation if it exists, otherwise return nil.
Examples
This section shows simple examples of how you can use the method.
Variation v = optimizelyClient.getForcedVariation(βexperiment_1β, βuser1β);
var actualForcedVariation = Optimizely.GetForcedVariation("test_experiment", TestUserId);
var actualForcedVariation = optimizely.getForcedVariation("test_experiment", TestUserId)
var variation = optlyInstance.getForcedVariation('testExperiment', 'testUser');
var forcedVariation = optlyInstance.getForcedVariation('testExperiment', 'user1');
OPTLYVariation* variation = [self.projectConfig getForcedVariation:experimentKey userId:@"user_a"];
$forcedVariationKey = $optlyObject->getForcedVariation('test_experiment', 'test_user');
forced_variation = self.optimizely.get_forced_variation('group_exp_1', 'user_1')
variation_to_return = project_instance.config.get_forced_variation('test_experiment', 'test_user')
OPTLYVariation *variation1 = [self.config getForcedVariation:@βExperimentβ userId:@βusers1β];
Exceptions
None
See also
Side effects
None
Source files
The table lists the language/platform source files containing the implementations.
Language/Platform | Source files |
---|---|
Android | OptimizelyClient.java |
C# | Optimizely.cs |
Java | Optimizely.java |
JavaScript | index.js |
Node | index.js |
Objective-C and Swift | Optimizely.h |
PHP | Optimizely.php |
Python | optimizely.py |
Ruby | optimizely.rb |