The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI Reference
Dev guideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Create feature flags

Describes how to create and implement feature flags in Optimizely Feature Experimentation.

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 code. Flags let you control the full lifecycle of features. You can toggle a feature off to release code 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, letting you validate functionality and measure performance before rolling it out broadly.

You can manage your flags in one interface. The following sections cover creating, editing, and archiving a flag.

Create a flag

To create a flag, go to Flags > Create New Flag:

  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.

    📘

    Note

    Optimizely Feature Experimentation automatically assigns a key to the flag based on this name. You use the flag key to implement the flag in your application's code.

    Flag keys cannot be changed after they are created.

  2. Optionally, enter a Description.

  3. Click Create Flag to save your flag.

    • Optimizely Feature Experimentation automatically creates a read-only flag_off variation for this flag, which you use as the control in experiments.
    • Optimizely Feature Experimentation automatically creates two environments: Production and Development.

Implement the feature flag

📘

Note

Before you can implement the flag, you must decide how to pass user identifiers to Optimizely Feature Experimentation, so that Optimizely Feature Experimentation 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 Feature Experimentation 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
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
var user = optimizely.CreateUserContext("user123", new UserAttributes { { "logged_in", true } });
var decision = user.Decide("flag_1");
var enabled = decision.Enabled;
// Decide if user sees a feature flag variation
var user = await flutterSDK.createUserContext(userId: "user123");
var decideResponse = await user.decide("product_sort");
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
const user = optimizely.createUserContext('user123', { logged_in: true });
const decision = user.decide('flag_1');
const enabled = decision.enabled;
// Decide if user sees a feature flag variation
$user = $optimizely->createUserContext('user123', ['logged_in' => true]);
$decision = $user->decide('flag_1');
$enabled = $decision->getEnabled();
# 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
var decision = useDecision('flag_1', null, { overrideUserAttributes: { logged_in: true }});
var enabled = decision.enabled;
# Decide if user sees a feature flag variation
user = optimizely_client.create_user_context('user123', {'logged_in' => true})
decision = user.decide('flag_1')
decision.enabled
// 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

For more detailed examples of each SDK, 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.

The Decide method separates developing and releasing code from the decision to turn a flag on. Your flag rules determine the value this method returns. For example, the method returns false if the current user is assigned to the control or "off" variation in an experiment.

Next steps

To deliver feature flag configurations, see Create flag variations.