Skip to content

Targeting & Rollouts

Every Feature in GrowthBook has a set of Rules per environment (e.g. dev, production). When the SDK calls isOn() or getFeatureValue(), GrowthBook walks through those rules from top to bottom. The first rule whose targeting condition matches the current user’s attributes is applied and its value is returned. If no rule matches, the Feature’s default value is returned.

This top-down, first-match model gives you precise control: you can force a value for internal users, then run a percentage rollout for everyone else, and the two rules will never interfere.

#LessonWhat you will learn
1Overview (this page)How rule evaluation works end-to-end
2Targeting AttributesDefining and passing user attributes to the SDK
3Targeting ConditionsFiltering users by attribute value in a rule
4Percentage RolloutsGradually releasing a flag to a percentage of users
5Forced Values & Saved GroupsForcing specific values and reusing user segments
import { GrowthBook } from '@growthbook/growthbook';
const gb = new GrowthBook({
apiHost: 'https://cdn.growthbook.io',
clientKey: 'sdk-YOUR_DEV_KEY',
});
await gb.init({ timeout: 2000 });
// Tell GrowthBook who the current user is
gb.setAttributes({
id: 'user-123',
country: 'TH',
plan: 'pro',
});
// Boolean flag
const showBanner = gb.isOn('promo-banner');
// Flag with a typed default
const checkoutVersion = gb.getFeatureValue('checkout-version', 'v1');
import { GrowthBook } from '@growthbook/growthbook';

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

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

// Tell GrowthBook who the current user is
gb.setAttributes({
  id: 'user-123',
  country: 'TH',
  plan: 'pro',
});

// Boolean flag
const showBanner = gb.isOn('promo-banner');

// Flag with a typed default
const checkoutVersion = gb.getFeatureValue('checkout-version', 'v1');
GrowthBook has two rules on a flag: rule A (targets beta users) and rule B (50% rollout) below it. A beta user visits. Which rule is applied?
What value does GrowthBook return when none of the rules on a feature match the current user?
What does `gb.setAttributes(...)` do?