Platform
Feature Toggles

Feature Toggles

You might also know them as feature flags. They are a powerful technique, allowing you to modify system behavior without changing code. They are used to hide, enable or disable certain features during runtime. This can be useful for developers to test features in production, release features to certain users, or to gradually roll out features to all users.


Creating a Feature Toggle

You can create a Feature Toggle either in the Overview or Feature Toggles tab of a project. You will be asked to provide the following:

  • Key: An identifier for the feature toggle. It has to be unique and contain only letters, numbers, and hyphens.
  • Description: A description of the feature toggle. (Optional)
  • Project: The project the feature toggle belongs to.

Treatments

What are treatments?

Treatments are the different states a feature toggle can be in. They are used to define the behavior of the feature toggle.

This is the panel where you can add, edit, and delete treatments.

Feature toggle treatments

  • You can identify a treatment by its name. To change it simply click on the treatment name.
  • The percentage of users that will receive this treatment. You can modify the amount by clicking on the percentage input.

You can then access them from your code either by using one of the SDKs or the API.

Warning

Remember to always cover control treatment in your code. This treatment is returned when the feature toggle is not found or when the SDK is not yet initialized.


Targeting rules

You can also define targeting rules for each treatment. These rules allow you to target specific users or groups of users.

That's how the targeting rules panel looks like:

Feature toggle targeting rules

Let's dive a bit deeper into what's going on in here:

  • You can read the targeting rules in the same way you can read code. Targeting rules always start with if statement, it can have if-else statements in the middle and always ends with an else statement.
  • The Property name, Handler, and Value define a condition. When the condition is met, the user will receive a treatment based on either Serve or Distribute block, depends on which one you select as active.
  • The Serve block allows you to serve a specific treatment to the user.
  • The Distribute block allows you to distribute treatments based on the percentage of users that will receive it.
  • You can add if-else statements by clicking on the Add condition button, they will go in between the if and else statements, and they work in the exact same way as if statements do.
  • Finally, there is an else statement. This block will be executed if none of the conditions are met.

Deleting a Feature Toggle

To delete a feature toggle, you can click on the delete button in the feature toggle Settings tab.

Deleting a feature toggle is irreversible

Remember to remove all references to the feature toggle in your code before deleting it. If you don't, your code will break.