Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySumbit a ticketLog In
GitHubNuGetDev CommunitySumbit a ticket

Feature variables

Feature variables enable you to avoid hard-coding variables in your application. Instead of updating the variables by deploying, you can update them remotely in the Optimizely app.

As an example, take the Flappy Bird video game, a game in which the variable gravity determines the difficulty of flying through oncoming gaps in pipes.

Gravity was hard-coded in the application, but is now controlled remotely via an Optimizely feature variable. This enables Optimizely to dynamically assign different values you want to test for gravity to different users as part of experiment variations so you can find the right level of challenge for a game.


gravity feature variable for Flappy Bird. See Flappy Bird video game

Feature variables in experiments

You can add and configure more than one feature variable in a single experiment variation. First, configure a feature flag with several variables. Then, for each test variation, change one or more of the variable values. In the Flappy Bird example, a "difficult" variation could test a high gravity variable and a low pipe gap distance variable. An "easy" variation could test a low gravity and a large pipe gap distance variable.

Feature variables in rollouts

You can set different feature variables per audience and per environment for feature rollouts. For more information, see Introduction to rollouts.

How it works

Use feature variables anywhere you might normally use a hard-coded value. It is important to ensure that:

  • An Optimizely SDK client (or microservice) is available for that code context
  • You pass a consistent user ID.

You will get the value of a feature variable in your code with something like:

gravity_value = optly.getFeatureVariable('gravity', userId).

When this feature test is live, Optimizely:

  • Assigns a user to a variation based on your defined traffic allocation and audience.
  • Returns the appropriate feature variable value to your code for that user.

Note that if you edit the feature configuration for a feature test while it is running, the changes are reflected live in the running feature test.

Create a feature variable

For information on how to create feature variables, see Create feature variables.