The Full Stack Developer Guide Developer Hub

Welcome to the Full Stack Developer Guide developer hub. You'll find comprehensive guides and documentation to help you start working with the Full Stack Developer Guide as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Get Feature Variable

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 @Nullable Boolean getFeatureVariableBoolean(@Nonnull String featureKey,
                                                   @Nonnull String variableKey,
                                                   @Nonnull String userId,
                                                   @Nonnull Map<String, Object> attributes)
  
  

Double

Returns the value of the specified double variable.

public @Nullable Double getFeatureVariableDouble(@Nonnull String featureKey,
                                                 @Nonnull String variableKey,
                                                 @Nonnull String userId,
                                                 @Nonnull Map<String, Object> attributes)
  
  

Integer

Returns the value of the specified integer variable.

public @Nullable Integer getFeatureVariableInteger(@Nonnull String featureKey,
                                                   @Nonnull String variableKey,
                                                   @Nonnull String userId,
                                                   @Nonnull Map<String, Object> attributes)
  
  

String

Returns the value of the specified string variable.

public @Nullable String getFeatureVariableString(@Nonnull String featureKey,
                                                 @Nonnull String variableKey,
                                                 @Nonnull String userId,
                                                 @Nonnull Map<String, String> attributes)
  
  

Version

SDK v3.0, v3.1

Description

Each of the Get Feature Variable methods follows the same logic as Is Feature Enabled:

  1. Evaluate any feature tests running for a user.
  2. 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 won't be counted until you call Is Feature Enabled. If you don't call Is Feature Enabled, you won't see any visitors on your results page.

Parameters

Required and optional parameters in Java are listed below.

Parameter
Type
Description

featureKey
required

string

The feature key is defined from the Features dashboard; see Use feature flags.

variableKey
required

string

The key that identifies the feature variable. For more information, see: Define feature variables.

userId
required

string

The user ID string uniquely identifies the participant in the experiment. For more information, see: Identify users.

attributes
required

map

A map of custom key-value string pairs specifying attributes for the user that are used for audience targeting and results segmentation. Non-string values are only supported in the 3.0 SDK and above.

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.

Example

Map<String, Object> attributes = new HashMap<>();
attributes.put("device", "iPhone");
attributes.put("lifetime", 24738388);
attributes.put("is_logged_in", true);

Double featureVariableValue = optimizelyClient.getFeatureVariableDouble("my_feature_key", "double_variable_key", "user_123", attributes);

Side effects

In SDKs v3.1 and later: Invokes the DECISION notification listener if this listener is enabled.

Source files

The language/platform source files containing the implementation for Java is Optimizely.java.

Updated 8 months ago


Get Feature Variable


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.