Returns a variation where the visitor will be bucketed, without triggering an impression.
This method takes into account any user attributes
passed in, to determine if the user is part of the audience that qualifies for the experiment.
Version
SDK v2.1
Description
Takes the same arguments and returns the same values as Activate, but without sending an impression network request. The behavior of the two methods is identical otherwise.
Use Get Variation if Activate has been called and the current variation assignment is needed for a given experiment and user. This method bypasses redundant network requests to Optimizely.
See Manage impressions for guidance on when to use each method.
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. |
user ID required | string | The ID of the user. |
attributes optional | map | A map of custom key-value string pairs specifying attributes for the user. For more information, see: Define audiences and attributes. |
Parameter names
This section shows the specific parameter names for each supported language.
experimentKey
userId
attributes
experimentKey
userId
userAttributes
experimentKey
userId
attributes
experimentKey
userId
attributes
experimentKey
userId
attributes
experimentKey
userId
attributes
$experimentKey
$userId
$attributes
experiment_key
user_id
attributes
experiment_key
user_id
attributes
experimentKey
userId
attributes
Returns
The key of the variation where the user is bucketed or null
if the user does not qualify for the experiment. The example shows the return as specified for each supported language.
@return the variation for the provided experiment key, user id, and attributes
<returns>null|Variation Representing variation</returns>
@return the variation for the provided experiment key, user id, and attributes
@return {string|null} variation key
@return {string|null} variation key
@return The variation into which the user is bucketed. This value can be nil.
@return null|string Representing the variation key
Returns:
Variation key representing the variation in which the user will be bucketed.
None if user is not in experiment or if experiment is not running.
@return [variation key] where visitor will be bucketed.
@return [nil] if the experiment is not running, if the user is not in the experiment, or if the datafile is invalid.
@return The variation into which the user was bucketed. This value can be nil.
Examples
This section shows simple examples of how you can use the method.
Variation v = optimizelyClient.getVariation(“test_id”, “test_user_id”, Collections.singletonMap("house", "Gryffindor"));
var result = Optimizely.getVariation("test_experiment", “user_1”, {"abc", "43" });
testUserAttributes.put("browser_type", "chrome");
Variation actualVariation = optimizely.getVariation('testExperimentWithAudiences', 'testUser', testUserAttributes);
var getVariation = optlyInstance.getVariation('testExperimentWithAudiences', 'testUser', {"abc", "43" });
var variationKey = optlyInstance.getVariation('testExperimentWithFirefoxAudience', userId, {'browser_type': 'firefox'});
OPTLYVariation *variation = [self.decisionService getVariation:@"testExperiment6" experiment:experimentWhitelisted attributes:self.attributes];
$this->testUserId = 'testUserId';
$this->experimentKey = 'test_experiment';
$this->testUserAttributes = [
'device_type' => 'iPhone',
'company' => 'Optimizely',
'location' => 'San Francisco'
];
variationKey = $optlyObject->getVariation($this->experimentKey, $this->testUserId, $this->testUserAttributes);
variation_key = self.optimizely.get_variation('test_experiment',
'test_user',
attributes={'test_attribute': 'test_value_invalid'})
project_instance.get_variation('test_experiment_with_audience', 'forced_audience_user', 'browser_type' => 'wrong_browser')
OPTLYVariation *variation;
variation = [self.optimizely variation:@"testExperiment1" userId:@”user1”];
Exceptions
SDK | Exception | Meaning |
---|---|---|
Java | UnknownExperimentException | The experiment is malformed or doesn't exist in the datafile. |
See also
Side effects
None
Notes
Activate versus Get Variation
Use Activate when the visitor actually sees the experiment. Use Get Variation when you need to know which bucket a visitor is in before showing the visitor the experiment. Impressions are tracked by Is Feature Enabled when there is a feature test running on the feature and the visitor qualifies for that feature test.
For example, suppose you want your web server to show a visitor variation_1 but don't want the visitor to count until they open a feature that isn't visible when the variation loads, like a modal. In this case, use Get Variation in the backend to specify that your web server should respond with variation_1, and use Activate in the front end when the visitor sees the experiment.
Also, use Get Variation when you're trying to align your Optimizely results with client-side third-party analytics. In this case, use Get Variation to retrieve the variation and even show it to the visitor, but only call Activate when the analytics call goes out.
See Manage impressions for more information about whether to use Activate or Get Variation for a call.
Note
Conversion events can only be attributed to experiments with previously tracked impressions. Impressions are tracked by Activate, not by Get Variation. As a general rule, Optimizely impressions are required for experiment results and not only for billing.
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 |