Feature Flags

Feature flags are at the core of VWO's Feature Management and Experimentation capabilities. They allow you to control feature rollouts and conduct experiments.

get_flag()

The get_flag() function is used to fetch the status and variables of a feature flag for a given user.

get_flag_response = vwo_instance.get_flag('feature_key', { id: 'your_user_id'})

# check if feature is enabled
puts get_flag_response.is_enabled()

Parameter Definitions

ParameterTypeDescription
feature_key
Required
stringunique identifier for the particular feature flag that you're implementing. You will see this while creating a feature flag, and you can also find it under 'Settings' for the Feature Flag after creating it.
context
Required
hashContains information about the current user, including a required unique identifier for each user. Read more about userContext here.

Return Value

The get_flag() function returns a GetFlagResponse object, which has the following methods:

  • is_enabled(): Returns a boolean indicating if the feature is enabled for the user.
  • get_variables(): Returns a list of variables associated with the feature.
  • get_variable(key string, defaultValue hash): Returns the value of a specific variable.

Example Usage

get_flag_response = vwo_instance.get_flag('feature_key', { id: 'your_user_id'})

# check if feature is enabled
puts get_flag_response.is_enabled()
# get all variables
puts get_flag_response.get_variables()
# get specific variable
puts get_flag_response.get_variable('variable_key', 'default_value')

Remember that the feature flag must be defined in your VWO dashboard before using it in your code.