Get All Feature Variables

Evaluates and returns all feature variables for the specified feature flag.

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.

Sample call

function getAllFeatureVariables(featureKey, userId, attributes)

Version

SDK v4.1.0 and higher

Description

For each feature variable associated with the feature flag, Get All Feature Variables returns all feature variable keys. For each key, it returns either the default or the user-specific variable value, depending on which audience the user is bucketed into. For example:

  • If the user is in a "Beta" audience on a feature rollout, this method returns user-specific values: {"welcome_snippet": "you're in our beta!", "new_feature_color": "red"}.
  • If the user is in a feature tests's control_variation in which the feature is disabled, this method returns the default values: {"welcome_snippet": "", "new_feature_color": "grey"}.

Note that depending on the audience rules, this method can return a mix of default and user-specific variable values.

🚧

Important

Unlike Is Feature Enabled, the Get All Feature Variables method does 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 are listed below.

Parameter

Type

Description

featureKey
required

string

The feature key is defined from the Features dashboard.

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

Returns a JSON object containing feature variable keys and values. Returns null if feature key is invalid, returns an empty object if there are no feature variables.
For example:

{
   "double_key": 10.02,
   "int_key": 4243,
   "string_key": "staging",
   "bool_key": true,
   "json_key1": {
     "test": 123,
     "test_2": "en-us"
    },
   "json_key2": {
     "test_3": 1.4
    }
}

Example

var attributes = {
  'device': 'iPhone',
  'lifetime': 24738388,
  'is_logged_in': True,
}

var featureVariableValues = optimizelyClient.getAllFeatureVariables('my_feature_key', 'user_123', attributes);

See also

Get Feature Variable

Side effects

Invokes the DECISION notification listener if this listener is enabled. Sends only one notification for all variables.

Source files

The language/platform source files containing the implementation for Javascript is index.ts.


Did this page help you?