Targeting & Rollouts
How GrowthBook Evaluates a Flag
Section titled “How GrowthBook Evaluates a Flag”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.
Module lessons
Section titled “Module lessons”| # | Lesson | What you will learn |
|---|---|---|
| 1 | Overview (this page) | How rule evaluation works end-to-end |
| 2 | Targeting Attributes | Defining and passing user attributes to the SDK |
| 3 | Targeting Conditions | Filtering users by attribute value in a rule |
| 4 | Percentage Rollouts | Gradually releasing a flag to a percentage of users |
| 5 | Forced Values & Saved Groups | Forcing 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 isgb.setAttributes({ id: 'user-123', country: 'TH', plan: 'pro',});
// Boolean flagconst showBanner = gb.isOn('promo-banner');
// Flag with a typed defaultconst 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');