Skip to content

Targeting Attributes

Targeting attributes are key-value pairs that describe the current user or session — for example id, email, country, or plan. When the SDK evaluates a flag, GrowthBook compares the current user’s attributes against the conditions on each rule to decide which rule (if any) applies.

Attributes are entirely defined by you. GrowthBook has no built-in user model — you tell it what to know about each user by calling setAttributes.

Step 1 — Define attributes in GrowthBook

Section titled “Step 1 — Define attributes in GrowthBook”

Before the SDK can match on an attribute, GrowthBook needs to know it exists and what type it holds.

  1. In the GrowthBook sidebar, click Settings → Attributes.
  2. Click Add Attribute.
  3. Enter the Attribute name (e.g. country).
  4. Select the Data Typestring, number, boolean, secureString, or string[].
  5. Check Identifier if this attribute uniquely identifies a user (used as the hash key for bucketing in experiments and percentage rollouts).
  6. Click Save.

Repeat for every attribute your rules will reference.

Call setAttributes before evaluating any flag. GrowthBook uses whatever is set at evaluation time, so call it as early as possible in your request or session lifecycle.

import { GrowthBook } from '@growthbook/growthbook';
const gb = new GrowthBook({
apiHost: 'https://cdn.growthbook.io',
clientKey: 'sdk-YOUR_DEV_KEY',
});
await gb.init({ timeout: 2000 });
gb.setAttributes({
id: 'user-123',
country: 'TH',
plan: 'pro',
});
import { GrowthBook } from '@growthbook/growthbook';

const gb = new GrowthBook({
  apiHost: 'https://cdn.growthbook.io',
  clientKey: 'sdk-YOUR_DEV_KEY',
});

await gb.init({ timeout: 2000 });

gb.setAttributes({
  id: 'user-123',
  email: '[email protected]',
  country: 'TH',
  plan: 'pro',
});

Identifier attributes (such as id or deviceId) are used as the hash key when bucketing users in percentage rollouts and A/B tests. Checking the Identifier box in Settings tells GrowthBook this attribute can be used for stable, deterministic bucketing — the same user always lands in the same bucket.

Non-identifier attributes (such as country or plan) are used only for targeting condition matching. They filter which users a rule applies to, but they are not used to assign users to experiment variants.

What is the purpose of calling `gb.setAttributes(...)` in the SDK?
What is an "Identifier" attribute used for in GrowthBook?
Where do you define the attributes that GrowthBook rules can target?