Flag variations enable you to avoid hard-coding variables in your application. Instead of updating the variables by deploying, you can group them in a flag variation, then 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 flag variable. This enables Optimizely to assign different values dynamically that you want to test for
gravity to different users in different flag variations.
For example, a "difficult" flag 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 could compare these two variations in an A/B test so you can find the right level of challenge for a game.
Use flag variations anywhere you might normally use hard-coded values. It's important to ensure that:
- An Optimizely SDK client (or microservice) is available for that code context
- You pass a consistent user context.
Optimizely automatically assigns the right flag variation to the user based on the flag rules that apply to that user. However, if you want to directly get the value of a flag variable in your code, you can use the Get Feature Variable or Get All Feature Variables methods. For more information, see the corresponding topic for your language in the SDK guides.
When a flag rule is live, Optimizely:
- Assigns a user to a variation based on your defined traffic allocation and audience.
- Returns the appropriate flag variable values to your code for that user.
Note that if you edit a flag variation while a flag rule is running, the changes are reflected live.
For information on how to create flag variations, see Create flag variations.
Updated 21 days ago