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 at your server and used to control the user's experience in your codebase.

getVariable()

// const featureFlag1 = await vwoClient.getFlag('feature_key', userContext);

//fetches and returns the value of the specified variable
const intVar = featureFlag1.getVariable('int_variable_key');

the getVariable() function requires just one argument, that is the 'int_variable_key' in the above example, which would be the unique key corresponding to a particular "Variable", as defined under Feature Flag > Variables.

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 FME application.

getVariables()

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

// Returns the value of a single variable  
const variable1 = featureFlag.getVariable("themecolour", "white");

// Returns an array of all relevant variables and their values for a given feature flag  
const allVariables = featureFlag.getVariables();

What’s Next