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

EDIT ON GITHUB

Targeting users with flags

Read time: 10 minutes
Last edited: Jul 28, 2021

Overview

This topic explains how to use a flag's Targeting tab to control which users see a variation of a feature flag. Configuring which users see which variation of a flag is referred to as a flag's targeting.

You can use the Targeting tab to roll features out for internal testing, private betas, or usability tests before performing a broader rollout. You can even set expiration dates for flag targeting if you know you only want users to see a flag for a specific period of time.

While the Targeting tab uses the language of targeted "users", a user can be any identifier that uniquely corresponds to a target. You can target users of your application, email addresses, systems, services, machines, resources, or anything else that can be uniquely identified.

Assigning users to a variation

The "Target individual users" section of the targeting tab allows you to assign individual users to a particular flag variation.

Only target small numbers of users individually

We recommend using individual user targeting for very small numbers of individual users. Targeting more than 10,000 users individually may cause performance degradation, because the SDK takes longer to initialize when the targeting rules payload is large. To learn more about targeting many users, read Targeting rules based on user attributes.

If your application is already sending data back to LaunchDarkly, you can search for users by name, email address, or user key. These strings are case sensitive. Hover over the user row to see more attributes for that user.

If you need to target a user that LaunchDarkly doesn't know about, you can enter their key manually. These users display in yellow until they encounter a feature flag.

In the screenshot below, we see which users are seeing the first variation of a flag. That flag is targeted to them. This means that these users will see that flag variation when they access the flag.

A flag with users targeted.
A flag with users targeted.

Removing targeted users

You can remove a user from a flag's targeting list by clicking the user's name. To do this:

  1. Navigate to the flag's Targeting tab.
  2. In the "Target individual users" section, find the name of the user you wish to remove.
  3. Click the X next to their name to remove them:

A user in the flag's targeting section, with the X to remove called out.
A user in the flag's targeting section, with the X to remove called out.

Scheduling removal dates for user targeting

Scheduling removal dates is a Pro and Enterprise feature

Scheduling removal dates is available to customers on a Pro or Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.

You can schedule a removal date and time for each individual user who is targeted by a flag. By doing this, you can specify a future date and time after which the user will no longer be targeted for the specific flag. You can do this for existing users, or when you create a new user.

This is useful if you want to give users trial access to a feature, run a controlled beta test, or just keep your flags organized by not having too many flags at work at once.

You can also schedule a user to be removed from a segment, rather than from flag targeting. To learn more, read Scheduling user removal from segments.

To set a targeting removal date:

  1. Navigate to the flag dashboard and select the flag for which you want to configure a removal date. The flag's Targeting tab appears.
  2. In the "Target individual users" section, click the name of the user for which you wish to set a removal date.
  3. In the "Remove user on" section, click to expand a calendar view:

The removal scheduling calendar.
The removal scheduling calendar.

  1. Set a date and time for the user to be removed from the flag.
  2. Click Apply.
  • If approvals are not required, the user is now scheduled for removal on the date and time you specified.
  • If approvals are required for scheduled removal dates, click the Request Approval button in the upper right. The Request Approval screen appears:

The request approval screen.
The request approval screen.

  1. Enter a Description to add context that helps your reviewers understand the changes you made.
  2. (Optional) If necessary, you can edit your flag changes by clicking the Edit button.
  3. Choose one or more reviewers from the Reviewers dropdown.
  4. Click Request approval.

The people you chose from the dropdown each receive an email asking them to approve your flag changes. The flag's Targeting page also updates with an icon to indicate that there are pending changes waiting for review.

Additionally, when you add a user to a flag, you can schedule them for removal later by clicking Add + Schedule Removal.

Here is an image of the user targeting field:

The user targeting field with the "Add + Schedule Removal" option called out.
The user targeting field with the "Add + Schedule Removal" option called out.

Targeting rules based on user attributes

In addition to targeting individual users, LaunchDarkly lets you target segments of users by constructing rules.

Each rule has four parts:

  • a description, which names the rule
  • an attribute, which defines the scope of the flag's impact, such as only impacting an email address
  • an operator, which sets differentiating characteristics of the attribute, such as limiting the attribute to emails that end with certain extensions. If a rule specifies multiple values for the operator to track, the operator iterates over the array.
  • a user value, which identifies a user or resource by a value you specify, such as @gmail.com.

Here is an example of a rule that serves true to all users whose email address ends with @gmail.com.

To write this rule, specify the attribute as email, the operator as ends with, and the user value as gmail.com. Click Save Changes to apply the rule.

Here is an image of a user targeting rule:

A user targeting rule.
A user targeting rule.

Operators

LaunchDarkly supports the following operators:

OperatorAttribute typeMeaning
is one of (=), is not one of (!=)string, number, boolean, dateexact match
ends with, does not end withstringstring suffix match
starts with, does not start withstringstring prefix match
matches, does not matchstringregular expression match
contains, does not containstringsubstring match
greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=)numbernumeric comparisons
before, afterdatedate comparisons
user is in segment, user is not in segmentsegment namesuser is included or excluded by the targeting rules for the named segments. Read more about Building user segments.
semantic version is one of (=), is not one of (!=), greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=)stringSemantic version comparison. Valid string attributes must follow the semantic versioning specification, though we allow the PATCH version to be omitted (so that, e.g. `2.0` is considered a valid semantic version).

Date comparisons

Dates require UNIX formatting

Dates specified in the user object should be formatted in UNIX milliseconds (UNIX epoch * 1000). To learn more about UNIX date formatting, or convert a date and time to UNIX milliseconds read Current Millis.

Required SDK versions for semantic versions

Older versions of our server SDKs do not support semantic version operators. Minimum SDK versions are:

Go: v3

Node: 3.4.0

Python: 4.3.0

Ruby: 2.5.0

.NET: 3.6.1

Java: 2.6.0

PHP: 2.5.0

No updates are required for Android, iOS, or JavaScript.

Built-in attributes

LaunchDarkly includes some useful built-in attributes for users. All of them are strings with the exception of anonymous:

Attribute KeyAttribute Example ValueNote
key"1f2e2d3a"Required for evaluation. This should be unique for each user.
secondary"2398127"If provided, this attribute is used with a user's key to generate a variation in percentage rollouts.
ip"10.10.10.10"This attribute must be an IP address.
email"user@example.com"
name"Jill Jones"
avatar"http://example.com/avatar.png"This attribute must be an absolute URL to an avatar image for the user.
firstName"Jill"
lastName"Jones"
country"Uganda"
anonymous"true"This is a Boolean value. This attribute prevents the user from appearing on the dashboard. Setting anonymous to false is not the same as omitting it. If you have a flag rule that checks for anonymous being false, the rule will not match users for whom you did not set a value, because null attributes will never match a flag rule.
We do not provide built-in attributesWhile we provide all of these fields for you to fill in, the SDK does not automatically collect any information. If you want to target your users based on any of these attributes you must supply their values.

Anonymous users

Anonymous users work just like regular users, except that they don't appear on your Users page in LaunchDarkly. You also can't search for anonymous users on your Features page, and you can't search or autocomplete by anonymous user keys. This is keeps anonymous users from polluting your Users page. Anonymous users still count toward your monthly active user limit.

You still must generate a unique key for anonymous users. Session IDs or UUIDs work best for this.

Maintaining experience across anonymous and logged-in states

To associate pre-login (anonymous) behaviors with post-login (known) behaviors to get a singular view of a user flow, you should use a custom attribute, and the advanced option for percentage rollouts that allows you to rollout based on a different attribute. The steps to make this happen are as follows:

  • store a unique identifier for the anonymous user into a cookie. A session ID or UUID works well.
  • until the user logs in, use this unique identifier as both the user's key, and a custom attribute. The custom attribute could be named anything, but for this example it is named "uniqueId".
  • while the user is logged in, set the users key to their real (primary) user key, but continue to use to use the unique identifier stored in the cookie as the users "uniqueId" custom attribute.
  • for all flags (or at least those that may effect logged out users), use the advanced option for all percentage rollouts to do rollouts based on the "uniqueId" custom attribute.
Secondary attribute

The secondary attribute is a special attribute. The SDKs incorporate this attribute into the variation bucket assignment hash automatically when it is included in your user object. Unlike other attributes, you cannot use the secondary attribute in targeting rules.

Targeting users based on custom attributes

LaunchDarkly allows you to target users based on arbitrary custom attributes, which means you can control who sees features based on any criteria that you send to us.

Custom attributes and built-in attributes

Setting a custom attribute with the same key as one of the built-in attributes will cause the attribute to be ignored during feature flag evaluation. For mobile SDKs, the custom attributes os and device are automatically included with os and device data. You can override this by specifying them as custom attributes in your user object and setting your own values.

You can add multiple conditions to a rule. Users must meet all the conditions in a rule to match the rule. If any of the conditions are not met, the user will not match the rule. If a custom attribute has an array value, LaunchDarkly treats it as multiple values and allows any of the values within the array to match a rule.

Here, we've created a custom rule with two conditions. This rule serves true to all users whose email address ends with gmail.com and whose country is either USA or CANADA.

Here is an image of a rule with conditions:

A rule serving "true" to users affected by two conditions.
A rule serving "true" to users affected by two conditions.

When you've finished setting up the conditions for your rule, you can decide whether your users will receive one variation, or a percentage rollout across several variations.

Let's turn a feature on for a group of external beta testers. First, we need to ensure that our back end sends a custom attribute called groups that identifies users that should be in the beta_testers group:

1// Go SDK 5.0 and above
2import (
3 "gopkg.in/launchdarkly/go-sdk-common.v2/lduser"
4 "gopkg.in/launchdarkly/go-sdk-common.v2/ldvalue"
5)
6user := lduser.NewUserBuilder("foo@example.com").
7 Custom("groups", ldvalue.String("beta_testers"))
8
9// Go SDK 4.16-4.17
10import (
11 ld "gopkg.in/launchdarkly/go-server-sdk.v4"
12 "gopkg.in/launchdarkly/go-sdk-common.v1/ldvalue"
13)
14user := ld.NewUserBuilder("foo@example.com").
15 Custom("groups", ldvalue.String("beta_testers"))
16
17// Go SDK 4.15 and earlier
18custom := make(map[string]interface{})
19custom["groups"] = "beta_testers"
20user := ld.NewUser("foo@example.com")
21user.Custom = &custom

To learn more, read UserBuilder, ldvalue.

On the Targeting tab, we add a new rule, set the attribute name to groups, the operator to is one ofand enter beta_testers, the name of our group of beta testers.

Any users in the beta_testers group will see the new dashboard feature. We've also kept the feature on for our internal tester Ernesto, since there's still an Include rule for him.

Percentage rollouts

If you want to do a percentage rollout, select "percentage rollout" from the dropdown and allocate users accordingly.

Here is an image of the percentage rollout screen:

The percentage rollout screen.
The percentage rollout screen.

In this example, 25% of the beta_testers group see the new dashboard feature.

Experiment allocation

If you're using Experimentation, experiment allocation allows you more flexibility when selecting your experiment population and ensures accurate experiment results. To learn how to enable and use experiment allocation, read Allocating experiment traffic.

Percentage rollout logic

When you set up a percentage rollout, the variation a user receives is determined by the user's key. The percentage rollout logic generates a hash from the user's key or attribute, the user's secondary attribute (if provided), the flag's key, and a hidden salt attribute stored in the flag.

The SDK uses this hash to generate a percentage value for that user. That value, compared to the value set for the percentage rollout value, determines which variation a user receives. The hash has partitions from 1 to 100,000. When you assign flag variations, the hash assigns values from 1 to 100,000 to users in each partition, in order. For example, when you assign 50% to variation A, LaunchDarkly serves variation A to hash partitions from 1 to 50,000.

A common use case for percentage rollouts is to increment the percentage of users targeted by a flag over time until 100% of the users see one variation of a flag. When you change the percentage allocation of users to flag variations, those users are reassigned different flag variations based on their partition's position in the 1 to 100,000 hash list. For example, if you change the percentage of users seeing variation A from 50% to 70%, partitions 50,001 to 70,000 would be added to the set of partitions already seeing variation A.

To learn more about rollouts and variation assignments, read Rollouts.

Advanced Targeting: Percentage rollout variation assignment by attribute

In the "Advanced" area of the percentage rollout menu, you can assign variation buckets to users based on any attribute sent to LaunchDarkly. For example, you can roll out a feature to 20% of companies, whereby users will be assigned to a variation bucket based on the value of their company attribute. This ensures that LaunchDarkly treats all users with matching attribute-value pairs the same. If you choose a custom attribute for this purpose, it should have either string values or integer numeric values. For users with a custom attribute number that includes a fraction or has a value type besides string or number, the variation bucket assignment is undefined.

Default rule: targeting remaining users

LaunchDarkly defines a final default rollout rule for any users that don't match any of the previous sections on the page. As with other rules, you can choose to serve a specific variation, or apply a percentage rollout to any remaining users.

Here is an image of the percentage rollout screen:

A percentage rollout, set to 50%.
A percentage rollout, set to 50%.

Now, 50% of all users who have not been targeted by any other rules will receive true.

Conducting a Simple Rollout

If you do not want to target users based on user key or any custom attributes, you can simply use the default rule to control the flag's rollout for all users.

Setting the Off variation

When the toggle is turned off, LaunchDarkly will serve the 'off' variation for your feature flag. For boolean flags, the off variation is set to false by default. For multivariate flags, you select one of your custom variations. You can customize the 'off' variation for both boolean and multivariate flags in the Targeting tab.

If you do not specify an 'off' variation, then LaunchDarkly will return the Fallback variation defined in your code.

Evaluation order

The Targeting tab evaluates rules top-down. Imagine a highway with exits along the way. All of your users will start at the top and then gradually exit the highway when they match a rule.

If a user matches multiple rules, the first matching rule applies.

Here is a diagram representing rule matching behavior:

A tree diagram showing rule matching behavior.
A tree diagram showing rule matching behavior.

Here, we have two custom rules. Rules are evaluated top down, so in this example, the first rule (email ends with gmail.com and country is one of USA or Canada) is evaluated before the second rule (groups is one of beta_testers). If a user matched both rules, the first rule would take priority.

Here is an image of two targeting rules:

Two custom rules targeted at user groups.
Two custom rules targeted at user groups.

Rules can be re-ordered by clicking on the left edge of a rule and dragging it up or down.

User storage

The Users page shows only cached user information. User data is deleted after 30 days if a user has not been seen by LaunchDarkly for more than 30 days. The rationale behind this is that the system should be regularly calling variations on users which would cause them to appear in the dashboard through normal usage.

If the variations are being called less frequently than 30 days, the best solution would be to manually identify all of the users that you wish to be kept in the dashboard every 30 days.

Converting a rule into a segment

You may require complex targeting rules to successfully perform feature launches. You can convert a targeting rule into a reusable segment from the flag's Targeting page.

Here is an image of the "Convert individual user targets to segment" modal:

The "Convert to segment" modal.
The "Convert to segment" modal.

To convert a rule to a segment:

  1. Navigate to the flag's Targeting page.
  2. In the user targeting section or the rule matching section, click the three-dot menu of the rule you wish to convert. The overflow menu appears.
  3. Click Convert to segment. The "Convert to segment" window appears:

A flag rule, with the "Convert to segment" option called out.
A flag rule, with the "Convert to segment" option called out.

  1. Give your segment a human-readable Name.
  2. (Optional) Add a Description.
  3. (Optional) Choose any Tags from the dropdown menu.
  4. Click Save segment. A confirmation appears indicating that you've created a new segment.

After you click "Convert to segment", targeted users are cleared. A new segment rule targeting the newly created segment test-12345 appears at the top of the list of targeting rules.

Here is an image of the targeting section:

The targeting section, with the new segment called out.
The targeting section, with the new segment called out.