Feature Flag Targeting
Targeting Attributes
Feature values can be targeted to specific users or groups of users. In order for this to work, you must pass targeting attributes into the GrowthBook SDK and also list them in the GrowthBook App.
This is an example of specifying the targeting attributes in the SDK:
growthbook.setAttributes({
id: user.id,
email: user.email,
country: user.country,
url: window.location.href,
userAgent: navigator.userAgent,
admin: user.isAdmin,
age: user.age,
});
You can update the attributes in the GrowthBook App under SDK Connections > Attributes:
The actual values of the targeting attributes (e.g. the user ids, emails, etc.) are never sent to GrowthBook. They are only stored in memory locally within the SDK. This architecture eliminates huge potential security holes and keeps your user's PII safe and secure.
Each attribute has 3 parts:
- The attribute name itself. This is how the attribute will be referenced in the SDK.
- The data type of the attribute
- Whether it's an identifier. Identifiers are attributes which uniquely identify something - typically either a person, account, company, or device- and are used for experiment assignments.
Attribute Data Types
GrowthBook supports the following attribute data types:
- Boolean - true or false
- Number - Floats or integers
- String - freeform text
- Enum - When there are only a small list of pre-defined values it could take
- Secure String - Like a string, but the values will be hashed before passing to the SDK
- Array of Strings - useful for things like "tags"
- Array of Numbers - useful anytime you have multiple numeric values
- Array of Secure Strings - an array of secure strings useful for passing multiple values that you want to keep secure
Saved Groups
In addition to targeting by attributes, GrowthBook also the concept of Saved Groups, which make it easy to target the same group of users across multiple features/experiments.
There are two types of Saved Groups:
- Inline Saved Groups - Pick an attribute and define a list of values directly within the GrowthBook UI. For example, you can make an
Admin
group and add theuserId
of all of your admins. - Runtime Saved Groups - Determine group membership in your application at runtime. For example, you can have a
Premium User
group and your application can pass into the SDK whether or not the current user is premium.
Runtime Saved Groups
Runtime groups require some changes to your SDK integration.
Every runtime group has a unique Group Identifier. You need to include a special attribute in your integration named $groups
that contains an array of these identifiers as strings.
Here's an example using our Javascript SDK:
// Build an array of groups
const groups = [];
// Use whatever custom logic you need to determine group membership
if (isPro()) {
groups.push("premium"); // "premium" is the Group Identifier
}
// Include it as a special `$groups` attribute:
const attributes = {
id: "123",
loggedIn: true,
"$groups": groups,
}
// Create your GrowthBook instance and include the special `$groups` attribute
const gb = new GrowthBook({
attributes: attributes,
// ... other options
});