Variables
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()
// Get the variable value for the given variable key and default value
val variable1 = featureFlag.getVariable("variable_key", "default-value1")
// Get the variable value for the given variable key and default value
String variable1 = (String) featureFlag.getVariable("variable_key", "default-value1");
the getVariable() function requires two arguments, 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 and the second one being the default value for this 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
// To get value of a single variable
val variable1 = featureFlag.getVariable("variable_key", "default-value1")
// To get value of all variables in object format
val getAllVariables = featureFlag.getVariables()
// Returns the value of a single variable
String variableValue = featureFlag.getVariable("stringVar", "default-value");
// Returns an array of all relevant variables and their values for a given feature flag
List<Map<String, Object>> allVariables = featureFlag.getVariables();
Updated about 2 months ago