• HOME
  • INTEGRATIONS
  • SDKS
  • GUIDES
  • API DOCS
No results for ""
EXPAND ALL
launchdarkly.com

EDIT ON GITHUB

Creating a feature flag

Read time: 4 minutes
Last edited: Aug 21, 2020

Overview

This topic explains how to create feature flags in LaunchDarkly. You can use feature flags in any aspect of your application, from the customer-facing UI to the backend.

In the LaunchDarkly UI, you can create a new flag, clone and modify an existing flag to create new ones, and set default variations for flags.

You can always use the API instead

You can also use the LaunchDarkly API to create and manage feature flags, as well as do many other tasks. LaunchDarkly is an API-first product, so everything you can do in the LaunchDarkly API is also available as an API endpoint. To learn more, read our REST API Documentation.

Creating a feature flag

You can create and modify feature flags from the dashboard.

To learn more about the dashboard, read The dashboard.

To create a feature flag:

  1. Log into LaunchDarkly. The dashboard appears.
  2. Click New. The "Create a feature flag" screen appears.

The dashboard, with the New button called out.
The dashboard, with the New button called out.

  1. Enter a unique, human-readable Name.
  2. Enter a unique flag Key. You'll use this key to reference the flag in your code. A suggested key auto-populates from the name you enter, but you can customize it if you wish.
  3. (Optional) Enter a Description of the flag. A brief, human-readable description helps your team members understand what the flag is for.
  4. (Optional) Click into the Tags dropdown and choose one or more tags for your flag.
Tags let you sort flags into groups

Tags are useful for managing flag permissions using custom roles. For example, you can tag a flag as "Marketing" and "DevOps", and then use these tags to determine who has read or write access for the flag. To learn more, read Custom roles.

  1. (Optional) In the "Client-side SDK flag availability" section, check the SDKs using Mobile Key and/or SDKs using client-side ID boxes to designate which SDKs the flag should be available to. To learn more, read Making flags available to client-side and mobile SDKs.
  2. Choose an option in the Flag variations dropdown. To learn more, read Flag variations.
  3. (Optional) Specify details for your Variation. To learn more, read Flag variations.
  4. (Optional) Change the default variations for the flag's on and off states. To learn more about default variations, read Setting default variations.
  5. (Optional) Select the This is a permanent flag checkbox.
  6. (Optional) Select the Make this flag available to client-side SDKs checkbox. If you choose this option, the flag will be pushed out to client-side SDKs.
  7. Click Save Flag.

The Create a feature flag screen.
The Create a feature flag screen.

That's it! You just created a feature flag. You can see it in the dashboard.

Making flags available to client-side and mobile SDKs

When you create a flag, you can choose to expose the flag to SDKs which use client-side ID, SDKs which use mobile keys, or both. By default, flags are only available to server-side SDKs. If you're using a client-side SDK, you must make each flag you wish to appear on the frontend available to the client.

The "Client-side SDK availability" section of the flag creation screen.
The "Client-side SDK availability" section of the flag creation screen.

Making flags available to client-side SDKs, specifically to SDKs for mobile devices, may have security implications you should consider. SDKs for mobile devices use mobile SDK keys, which are readily available to mobile apps. A leaked mobile SDK key allows a backdoor around JavaScript's SecureMode, which can allow the holder to find out the value of every flag for any user even without knowing the SDK key that is used to hash the user key in Secure Mode.

To learn more, read Client-side and server-side SDKs.

Configuring the same flag in different environments

All environments within a project have the same set of feature flags. When you create a new feature flag, it is created in every environment in your LaunchDarkly project. That flag is scoped to your entire project.

Understanding flag scopes

Flag scoping refers to the parts of LaunchDarkly where a flag is available or used. If a flag is scoped at the project level, it is available to all environments within the project, because projects contain environments. To learn more about projects, read Projects.

To learn more about environments, read Environments.

Flag configuration settings are specific to each environment. The changes you make in one environment do not apply to the same flag in any other environment. If you want to, you can configure the same flag in a unique way for every environment you have.

To configure a flag in a different environment:

  1. Navigate to the dashboard.
  2. Click the environment name in the top left corner. The Switch environment menu appears.

The Switch environment menu.
The Switch environment menu.

  1. Search for the environment you wish to switch to and click on it, or choose it from the list. The dashboard for the new environment appears.
Look for the header change
You know you're in a different environment because the name displayed in the top left corner changes when you select that environment from the list.
  1. Find the flag you wish to modify and make whatever changes you like.

Setting default variations

When you create a feature flag, some of its variations are designated as default variations. You can accept the defaults or change them. When you do this and click Save Flag, the flag is created across all environments in your project with these variations set as its on and off values.

To learn more about default flag variations, read Changing default flag variations.

The default variation options on the flag creation screen.
The default variation options on the flag creation screen.

Cloning flags

You can also create new flags by cloning existing flags. Instead of creating an entirely new flag with complicated configuration, you can clone and modify an existing flag with similar configuration.

When you clone a flag, LaunchDarkly makes a new flag and copies the original flag's targeting configuration for all environments, including default variations and whether the flag is toggled on or off.

To clone a flag:

  1. Navigate to the dashboard.
  2. Find the flag you wish to clone and click its name. The flag detail page opens.

A flag on the dashboard.
A flag on the dashboard.

  1. Click into the flag's Settings tab. The flag Settings menu opens.
  2. Click Clone This Flag. The "Clone feature flag" screen appears.

The Clone This Flag button.
The Clone This Flag button.

  1. Enter a unique, human-readable Name.
  2. Enter a unique flag Key. You'll use this key to reference the flag in your code. A suggested key auto-populates from the name you enter, but you can customize it if you wish.
  3. (Optional) Enter a Description of the flag. A brief, human-readable description helps your team members understand what the flag is for.
  4. (Optional) Click into the Tags dropdown and choose one or more tags for your flag.
Tags sort flags into groups

Tags are useful for managing flag permissions using custom roles. For example, you can tag a flag as "Marketing" and "DevOps", and then use these tags to determine who has read or write access for the flag. To learn more, read Custom roles.

  1. Click Save Flag. You are taken to the new flag's details page.

The flag cloning configuration screen.
The flag cloning configuration screen.

The new flag also appears in the dashboard, where you can search for it or access it any time.