Targeting with rules

Back in lesson 1, we talked about using feature flags to separate deployment from release, and the power of testing in production: testing a deployed change before releasing it to all users.

Let's say that users of our game have keys that start with user, but the developers have keys that start with dev. You can create a targeting rule that recognises developer keys and enables the flag for them.

To create the rule:

  1. Return to your Space Mode flag's targeting page in LaunchDarkly.
  2. Under Target users who match these rules, add a rule:
    • key
    • starts with
    • dev
    • serve true
  3. Click Save changes.

The rule should look like this:

Create a targeting rule

In Replit, see what happens when you click on the "Toggle Runner" heading and change the key to user456, then dev123. You didn't need to make any code changes to change the targeting! Furthermore, this targeting rule allows developers to deploy the Space Mode feature and test it in the production environment without releasing it to users.

If you play with the targeting rules interface, you'll see that you can use many kinds of criteria when creating rules. They can evaluate different operators against any of the user attributes that your code supplies.

On the next page, we'll talk about feature flag use cases.