HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In

Create feature flags

Describes how to create and implement feature flags in Optimizely Full Stack Flags version.

Feature flags, also known as feature toggles or permission toggles, are a software development technique that lets you turn certain functionality on and off without deploying new code. Flags allow for better control over the full lifecycle of features. You can toggle a feature off to release code quickly without exposing it to users. You can also roll it out to a fraction of your user base to minimize the impact of the launch, allowing you to validate functionality and measure performance before rolling it out broadly.

In Optimizely, you can manage all your flags in one interface. The following sections cover how to create, edit and archive a flag.

Create a flag

To create a flag, navigate to Flags>Create New:

Create flagsCreate flags

Click to enlarge the image

  1. In the Name field, give the Flag a unique name. (Valid keys contain alphanumeric characters, hyphens, and underscores, are limited to 64 characters, and cannot contain spaces.)

Optimizely automatically assigns a key to the Flag based on this name. You will use the flag key to implement the Flag in your application code. Flag keys cannot be changed after they are created.

  1. Optionally, enter a Description.

  2. Click Create Flag to save your new Flag.

    • Optimizely automatically creates a read-only flag_off variation for this Flag, which you use as a control in experiments.

Implement the feature flag

πŸ“˜

Prerequisite

Before you can implement the flag, you must decide how to pass users to Optimizely, so that Optimizely can give each user a consistent experience of either an enabled or disabled flag. For more information see Handle user ids.

After you create the Flag in the Optimizely dashboard, you need to integrate it with your application code. Use the Decide method to enable or disable the Flag for a user:

// Decide if user sees a feature flag variation
let user = optimizely.createUserContext(userId: "user123", attributes: ["logged_in":true])
let decision = user.decide(key: "flag_1")
let enabled = decision.enabled
// Decide if user sees a feature flag variation
user := optimizely.CreateUserContext("user123", map[string]interface{}{"logged_in": true})
decision := user.Decide("flag_1", nil)
enabled := decision.Enabled
# Decide if user sees a feature flag variation
user = optimizely.create_user_context("user123", {'logged_in': True})
decision = user.decide("flag_1")
enabled = decision.enabled
// Decide if user sees a feature flag variation
$user = $optimizely_client->createUserContext('user123', ['logged_in' => true]);
$decision = $user->decide('flag_1');
$enabled = $decision->getEnabled();
# Decide if user sees a feature flag variation
user = optimizely_client.create_user_context('user123', {'logged_in' => true})
decision = user.decide('flag_1')
enabled = decision.enabled
// Decide if user sees a feature flag variation
var user = optimizely.CreateUserContext("user123", new UserAttributes { { "logged_in", true } });
var decision = user.Decide(key: "flag_1");
var enabled = decision.Enabled;
// Decide if user sees a feature flag variation
OptimizelyUserContext user = optimizely.createUserContext("user123", new HashMap<String, Object>() { { put("logged_in", true); } });
OptimizelyDecision decision = user.decide("flag_1");
Boolean enabled = decision.getEnabled();
// Decide if user sees a feature flag variation
var user = optimizelyClient.createUserContext('user123', { logged_in: true });
var decision = user.decide('flag_1');
var enabled = decision.enabled;
// Decide if user sees a feature flag variation
var decision = useDecision('flag_1', null, { overrideUserAttributes: { logged_in: true }});
var enabled = decision.enabled;
// Decide if user sees a feature flag variation
var user = await flutterSDK.createUserContext("user123");
var decideResponse = await user.decide("product_sort");
var enabled = decision.enabled;

For more detailed examples, see:

Adapt the integration code in your application. Show or hide the Flag's functionality for a given user ID based on the Boolean value your application receives Optimizely.

The goal of the Decide method is to separate the process of developing and releasing code from the decision to turn a flag on. The value this method returns is determined by your flag rules. For example, if the current user is assigned to a control or "off" variation in an experiment, the method returns false.

Next steps

To deliver feature flag configurations, see Create flag variations.