Create a feature flag

portrait de l'auteur Julie Trenque

Written by Julie Trenque

Updated on 06/15/2022

3 min

Advanced

Was this content useful?

What is feature management and feature experimentation?

This guide is designed to help you create and activate Feature flags in your mobile application (Android or iOS) or your website. For each use case, we provide SDKs in the main languages (PHP, Java, Swift, NodeJS…). You can have the complete list of our SDKs and follow the installation guidelines provided for each SDK.

Create a new project

Before creating any feature flag, you need to create a new project in your Kameleoon account. A project can be an environment (production, staging), a website or your mobile application (Android or iOS). 

Each project has its own sitecode, which uniquely identifies a project in your Kameleoon account. If you want to run feature flags across several of your applications and websites without having to duplicate them on each project, we recommend you set up only one site and use the same sitecode in all our SDKs.

Note: Your sitecode appears automatically in the feature flag creation page.

The sitecode is really important and it will be required in our SDK when you initialize the KameleoonClient object.

NodeJS SDK example

Create a new feature flag

Access the Feature flag creation page

On the side menu of the App, click on “Feature flags” to access the dedicated dashboard.

Then click on the “New feature flag” button.

Name your feature flag and choose the project on which you would like to activate this feature flag.

A feature key is automatically generated based on your feature flag name. You can update it based on your preferences.

Note: The feature key is the unique ID that enables you to identify the feature flag in your source code. Make sure to update it here before editing it in your source code.

Technical note: Check that the flag has been created and that you can retrieve it from your source code by using our SDK (by calling the activateFeature() method”). Then go back to the Kameleoon interface of your feature flag and continue the configuration steps.

You can associate a tag (which you can use to filter the dashboard list) and/or a description.

By default, your flag is OFF. You will be able to activate it once configured.

Structure of the Feature flag creation page

The Feature flag creation page consists of several blocks.

  • A header indicating the name of the flag, the associated sitecode (you can copy and paste it directly from here) and the feature key
  • An environment picker to set up your feature flag on each environment
  • A Rollout planner and Rule queue tab to define a rollout strategy for each environment
  • A Goals tab to define any goals you want to track or achieve within this environment (optional)
  • A Variables and code tab to define any variables for the chosen environment (optional)
  • A footer to view the date of the last backup, save the flag or delete it (via the 3-point menu).

Select an environment

Start by selecting the environment you want to work in (Production, Staging or Development). By default, the Production environment is selected. 

You will be able to define and apply different configurations (dedicated variables, goals and targeting) for your flag, based on the environment it is deployed on.

Technical note: With Kameleoon multi-environments feature flagging, you will have the possibility to use a new parameter named “environment” within the YAML configuration file to define environment types. In the case there is no environment specified within your YAML file, the configuration associated with the “Production” environment from your feature flag edition page will be applied by default.

For example, you can:

  • Activate your flag on two of your environments, Staging & Development;
  • Deactivate your flag on your Production environment.

Note: When your flag is ON on an environment, the circle on the left is green. When your flag is OFF, the circle is grey. When your flag is planned, the circle is blue.

Plan a rollout

This tab enables you to define a rollout strategy for your feature. It gives you an overview of the flag state and configuration for each environment type.

Note: By default, your feature flag is configured on “OFF” on each environment. This means that none of your users are exposed to this functionality.

Click on “+ Add a rule” to open the rule configuration menu.

Here you can select a variety of available release settings. Select a rule, then continue.

What are rules? Rules are a sequence of actions that can be scheduled or applied immediately for your feature flag in the selected environment. 

ACTIVATION rules

Turn ON

Use this rule to activate your feature flag. Selecting this rule will turn the flag on for all your audience. 

Continue to the next step where you will be presented with two options:

  • Apply the Turn On action immediately.
  • Apply the Turn On action at a specific date and time. Selecting this option will show a calendar and time selection drop-down for you to customize. Enter time, date and the timezone for when you’d like to plan this feature flag to automatically turn ON.
Turn OFF

Use this rule to disable your feature flag. Selecting this rule will turn the flag off for all your audience. 

Continue to the next step where you will be presented with two options, similar to the Turn On rule above.

  • Apply the Turn Off action immediately.
  • Apply the Turn Off action at a specific date and time. Selecting this option will show a calendar and time selection drop-down for you to customize. Enter time, date and the timezone for when you’d like to plan this feature flag to automatically turn OFF.

DELIVERY rules

Targeted delivery

Use this to turn ON your feature flag for a subset of your audience. You can define any custom segment and turn on your feature flag only for this segment. You can also use this rule to determine what percentage of your chosen audience the flag will be activated for.

Selecting this rule will require you to configure:

You can rollout your feature flag to specific groups of users who share common attributes. For this, you will need to define custom data and then build segments by combining custom data with OR/AND operators.

  • Exposure: What percentage of your defined segment will be exposed to the feature flag once it is turned on?
  • Scheduling: When to execute this rule, similar to the aforementioned Turn On and Off rules.

Note: By default, the selected timezone will be the one set for your customer account. You can then update it independently for each feature flag.

Progressive delivery

Use this rule when you want to gradually roll your feature out over a period of time.

Selecting this option allows you to customize the schedule and ramp-up of your release, as well as the audience for this rollout. 

Continue to the next step to configure:

You can rollout your feature flag to specific groups of users who share common attributes. For this, you will need to define custom data and then build segments by combining custom data with OR/AND operators.

  • Exposure: What percentage of your defined segment will be exposed to the feature flag once it is turned on?
  • Scheduling: When to begin the progressive rollout? Immediately or at a designated date and time, similar to the other rules. 

Note: By default, the selected timezone will be the one set for your customer account. You can then update it independently for each feature flag.

  • Start date of the rollout.
  • Initial exposure: What audience will immediately have the feature flag turned on for them? 
  • Increment for exposure at each step.
  • Time interval between increments.
  • Final exposure limit: Define the percentage at which you want the rollout to stop. Below this section, you will see a confirmation of when and at what exposure percentage the rollout will stop.

Once you have configured your rule, click Add at the bottom of the menu to add it to the rule queue.

You will see a notification confirming that your selected rule has been added.

Depending on the type and scheduling of the rule, it will have a status indicator next to it. 

The status of a rule can help you understand whether a rule is active or inactive.

For rules added in the queue, you can see a (vertical ellipses) menu displayed in the right corner of each rule. Clicking on it displays options to:

  • Edit rule
  • Delete rule

Note: Currently, you can edit or remove Planned rules only.

To learn how to manage your feature flags once created, please read our article on the Feature flags Dashboard.

Define goals

This step is optional.

Choose a goal/KPI you want to measure in our reporting tool for this feature flag. Learn how to create a goal

With this tab you can monitor specific KPIs if you wish. For example, you can see if the feature is being used, set up a click tracking…

Define variables & code

This step is optional.

Here you can configure variables and find some code examples depending on your SDK.

  • Variables

Optionally, you can define feature variables (Number, Boolean, String or JSON) to remotely update the content of your feature flags in production. There is no limitation in the number of feature variables you can create.

For example, if you feature is a new offer for premium customers but you are not sure about the discount code % you want to offer, you can create a “Discount percentage” variable to update your code remotely once the feature is live.

Note: Once the code is in production, you can change the value of this variable from Kameleoon without having to edit your code. For example, if you change the value from your flag configuration page on Kameleoon, it will automatically impact your flag in your source code.

  • Code examples

Choose your SDK language and use the sample code to set up the SDK in your application. The available languages are the following:

  1. Android
  2. Swift
  3. Java
  4. C#
  5. Node JS
  6. PHP
  7. Ruby
  8. Go
  9. Flutter
  10. Python

Implementation guidelines

Once your feature flag has been launched / activated, you will need to follow the developer documentation available for each SDK. In a nutshell, you will need to :

  • Install the SDK in your app or website. For web SDKs, you will need to provide credentials (client_id and client_secret) via a configuration file available in the SDK, which can also be used to customize the SDK behavior. You can ask your credentials to your Account Manager.
  • Initialize the KameleoonClient. Remember: you will need your sitecode here.
  • Activate the feature flag by calling the activateFeature() method of our SDK. This method usually takes a visitorCode and the featureKey (the one you have chosen when you have created your feature flag). The activateFeature() method returns a boolean value: true if the user should have this feature or false if not. Kameleoon will randomly expose your visitor to your feature flag (except if you have rolled out it to 100% of your users). If you have set up a segment for your feature flag, Kameleoon will only activate the feature if the user meets the conditions defined in your segment. For mobile SDKs, the initialization of the Kameleoon Client is not immediate, as it needs to perform a server call to retrieve the current configuration for all active feature flags. The runWhenReady() method of the KameleoonClient class allows to pass a callback function that will be executed as soon as the SDK is ready for use. It also allows the use of a timeout. Two methods must be implemented: onReady() and onTimeout(). The onReady() method will be called once the Kameleoon client is ready, and should contain the code that activates your feature flag. The onTimeout() method will be called if the specified timeout happens before the client is initialized.
  • (Optional) Retrieve the feature variables associated with your feature flag by calling the obtainFeatureVariable() method of our SDK. This method takes two input parameters: your feature Key and your variable Key. It will return the data as a java.lang.Object instance. Usually it should be casted to the expected type (the one defined on the web interface).
  • (Required if you use a segment in your feature flag) You can associate data with the current user. For this, you need to use the addData() method of our SDK. Data associated with the current user via this method is not sent immediately to our servers. It is stored and accumulated until it is sent automatically by the activateFeature() or trackConversion() methods, or manually by the flush() method. This allows you to control exactly when the data is flushed to our servers.
  • Track metrics to measure the success of your feature flag. You need to use the trackConversion() method. This method requires a visitorCode and a goal ID to track conversion on this particular goal. In addition, this method also accepts revenue as a third optional argument to track revenue. Only custom goals can be tracked in feature flags reports. The ID you need to use in the trackConversion() method is available in the custom goal creation popin.

  • In this article :