If a particular feature flag is enabled for a user, you can then fetch the required variables corresponding to that feature flag. These variables need to be first configured in VWO, and can then be fetched and used to control the user's experience in your codebase.

getVariable()

// get the variable value for the given variable key and default value
const variableValue = flagResult.getVariable('feature_flag_variable_key', 'default_value');

the getVariable() function requires two arguments, that is the 'feature_flag_variable_key' in the above example, which would be the unique key corresponding to a particular "Variable", as defined under Feature Flag > Variables, and the second one is the default-value of that variable.

Please note that the getVariable() function needs to be called on the feature flag object returned from the previous getFlag() function.

getVariable() returns the value of the specified variable :

  • For testing rules, this value will depend on which variation the user becomes part of (for testing rules).
  • For rollouts, this will return the default value of the variable.
  • For personalise rules, it will return the appropriate value of the variable depending on what you have configured in the personalise rule in the FM&E application.

getVariables()

Similar to getVariable(), but this function returns an array of objects, with the values of all variables connected to a feature flag

// get all variables
const flagResult: GetFlagResult = await vwoClient.getFlag('feature_key', userContext);
const allVariables = flagResult.getVariables();