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.
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.
You can set different feature variables per audience and per environment for feature rollouts. For more information, see Introduction to rollouts
Use feature variables anywhere you might normally use a hard-coded value. It's important to ensure that:
- An Optimizely SDK client (or microservice) is available for that code context
- You pass a consistent user ID.
You'll 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.
For information on how to create feature variables, see Create feature variables.
Updated about 2 years ago