Evaluates the specified feature variable of a specific variable type and returns its value.
This method is used to evaluate and return a feature variable. Multiple versions of this method are available and are named according to the data type they return:
This method takes into account the user attributes
passed in, to determine if the user is part of the audience that qualifies for the experiment.
Boolean
Returns the value of the specified boolean variable.
public bool? GetFeatureVariableBoolean(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null)
public @Nullable Boolean getFeatureVariableBoolean(@Nonnull String featureKey,
@Nonnull String variableKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes)
Optimizely.prototype.getFeatureVariableBoolean = function (featureKey, variableKey, userId, attributes) {
- (NSNumber *)getFeatureVariableBoolean:(nullable NSString *)featureKey
variableKey:(nullable NSString *)variableKey
userId:(nullable NSString *)userId
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
public function getFeatureVariableBoolean($featureFlagKey, $variableKey, $userId, $attributes = null)
def get_feature_variable_boolean(self, feature_key, variable_key, user_id, attributes=None):
def get_feature_variable_boolean(feature_flag_key, variable_key, user_id, attributes = nil)
- (NSNumber *)getFeatureVariableBoolean:(nullable NSString *)featureKey
variableKey:(nullable NSString *)variableKey
userId:(nullable NSString *)userId
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes
Double
Returns the value of the specified double variable.
public double? GetFeatureVariableDouble(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null)
public @Nullable Double getFeatureVariableDouble(@Nonnull String featureKey,
@Nonnull String variableKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes)
Optimizely.prototype.getFeatureVariableDouble = function (featureKey, variableKey, userId, attributes) {
- (NSNumber *)getFeatureVariableDouble:(nullable NSString *)featureKey
variableKey:(nullable NSString *)variableKey
userId:(nullable NSString *)userId
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
public function getFeatureVariableDouble($featureFlagKey, $variableKey, $userId, $attributes = null)
def get_feature_variable_double(self, feature_key, variable_key, user_id, attributes=None):
def get_feature_variable_double(feature_flag_key, variable_key, user_id, attributes = nil)
- (NSNumber *)getFeatureVariableDouble:(nullable NSString *)featureKey
variableKey:(nullable NSString *)variableKey
userId:(nullable NSString *)userId
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
Integer
Returns the value of the specified integer variable.
public int? GetFeatureVariableInteger(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null)
public @Nullable Integer getFeatureVariableInteger(@Nonnull String featureKey,
@Nonnull String variableKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes)
Optimizely.prototype.getFeatureVariableInteger = function (featureKey, variableKey, userId, attributes) {
- (NSNumber *)getFeatureVariableInteger:(nullable NSString *)featureKey
variableKey:(nullable NSString *)variableKey
userId:(nullable NSString *)userId
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
public function getFeatureVariableInteger($featureFlagKey, $variableKey, $userId, $attributes = null)
def get_feature_variable_integer(self, feature_key, variable_key, user_id, attributes=None):
def get_feature_variable_integer(feature_flag_key, variable_key, user_id, attributes = nil)
- (NSNumber *)getFeatureVariableInteger:(nullable NSString *)featureKey
variableKey:(nullable NSString *)variableKey
userId:(nullable NSString *)userId
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
String
Returns the value of the specified string variable.
public string GetFeatureVariableString(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null)
public @Nullable String getFeatureVariableString(@Nonnull String featureKey,
@Nonnull String variableKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes)
Optimizely.prototype.getFeatureVariableString = function (featureKey, variableKey, userId, attributes) {
- (NSString *_Nullable)getFeatureVariableString:(nullable NSString *)featureKey
variableKey:(nullable NSString *)variableKey
userId:(nullable NSString *)userId
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
public function getFeatureVariableString($featureFlagKey, $variableKey, $userId, $attributes = null)
def get_feature_variable_string(self, feature_key, variable_key, user_id, attributes=None):
def get_feature_variable_string(feature_flag_key, variable_key, user_id, attributes = nil)
- (NSString *_Nullable)getFeatureVariableString:(nullable NSString *)featureKey
variableKey:(nullable NSString *)variableKey
userId:(nullable NSString *)userId
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
Version
SDK v2.1
Description
Each of the Get Feature Variable methods follows the same logic as Is Feature Enabled:
- Evaluate any feature tests running for a user.
- Check the default configuration on a rollout.
The default value is returned if neither of these are applicable for the specified user, or if the user is in a variation where the feature is disabled.
Important
Unlike Is Feature Enabled, the Get Feature Variable methods do not trigger an impression event. This means that if you're running a feature test, events will not be counted until you call Is Feature Enabled. If you do not call Is Feature Enabled, you will not see any visitors on your results page.
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 |
---|---|---|
feature key required | string | The feature key is defined from the Features dashboard; see Use feature flags. |
variable key required | string | The key that identifies the feature variable. For more information, see: Define feature variables. |
user ID required | string | The user ID string uniquely identifies the participant in the experiment. For more information, see: Identify users. |
user attributes required | map | A map of custom key-value string pairs specifying attributes for the user. For more information, see: Define audiences and attributes. |
activateExperiment (Available on Android but deprecated) | Boolean | Set to true to activate the experiment, or false to not activate the experiment. |
Parameter names
This section shows the specific parameter names for each supported language.
featureKey
variableKey
userId
attributes
featureKey
variableKey
userId
userAttributes
featureKey
variableKey
userId
attributes
featureKey
variableKey
userId
attributes
featureKey
variableKey
userId
attributes
featureKey
variableKey
userId
attributes
featureFlagKey
variableKey
userId
attributes
feature_key
variable_key
user_id
attributes
feature_flag_key
variable_key
user_id
attributes
featureKey
variableKey
userId
attributes
Returns
The value of the variable, or null
if the feature key is invalid, the variable key is invalid, or there is a mismatch with the type of the variable. The example shows the return as specified for each supported language.
@return The value of the variable, or `null` if the feature key is invalid, the variable key is invalid, or there is a mismatch with the type of the variable.
<returns>string | Feature variable value or null</returns>
@return The value of the variable, or `null` if the feature key is invalid, the variable key is invalid, or there is a mismatch with the type of the variable.
@return {boolean|null} The value of the variable, or `null` if the feature key is invalid, the variable key is invalid, or there is a mismatch with the type of the variable.
@return The value of the variable feature. Null if the feature or variable could not be found.
@return The value of the variable, or `nil` if the feature key is invalid, the variable key is invalid, or there is a mismatch with the type of the variable.
@return string variable value / null
Returns
Value of the variable. None if:
- Feature key is invalid.
- Variable key is invalid.
- Mismatch with type of variable.
@return [<type specific>] The value of the variable, or `nil` if the feature key is invalid, the variable key is invalid, or there is a mismatch with the type of the variable.
@return feature variable value of type <datatype>.
Examples
This section shows simple examples of how you can use the method.
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
Boolean b = optimizelyClient.getVariableBoolean("test_variable", "userId", Collections.<String, String>emptyMap(), true);
Boolean booleanVariable = optimizelyClient.getFeatureVariableBoolean("my_feature_key", "boolean_variable_key", "user_1");
var doubleVariable = optimizelyClient.getFeatureVariableDouble('my_feature_key', 'double_variable_key', 'user_1');
var result = optlyInstance.getFeatureVariableBoolean('test_feature_for_experiment', 'is_button_animated', 'user1', { test_attribute: 'test_value' });
var booleanVariable = optimizelyClient.getFeatureVariableBoolean('my_feature_key', 'boolean_variable_key', 'user_1');
$integerVariable = $optimizelyClient->getFeatureVariableInteger('my_feature_key', 'integer_variable_key', 'my_user');
boolean_variable = optimizely_client.get_feature_variable_boolean('my_feature_key', 'boolean_variable_key', 'my_user')
boolean_variable = optimizely_client.get_feature_variable_boolean('my_feature_key', 'boolean_variable_key', 'user_1')
optimizelyMock = [self getOptimizelyMockForFeatureVariableType:@"double" variableKey:@"varDouble" expectedReturn:expectedValueString];
double val = [optimizelyMock getFeatureVariableDouble:featureKey variableKey:@"varDouble" userId:@”user1” attributes:nil];
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 |