What is a targeting rule?
Updated November 15, 2026
A targeting rule is a condition on a feature flag, such as "plan equals pro" or "country is Spain", that decides which value a user gets, using attributes the application passes in with each evaluation.
How do targeting rules work?
The application passes a context with each flag evaluation: a user ID (the targeting key) plus attributes such as plan, country or app version. The flag tool compares those attributes with the flag's rules and serves the matching value, or the default. How rules combine depends on the tool:
| Tool | Name | How rules combine |
|---|---|---|
| LaunchDarkly | Targeting rules, plus individual targets and prerequisites, used to "serve different variations to different end users" | In sequence: prerequisites, individual targets, then rules from top to bottom; the first match wins, else the default rule |
| Unleash | Activation strategies with constraints; constraints are "conditional rules that determine whether a strategy applies" | Constraints within a strategy are ANDed; strategies on a flag are ORed |
| flagd | targeting written in a modified JSON Logic |
One expression decides the variant |
Sources: LaunchDarkly targeting and flag evaluation sequence, Unleash activation strategies, flagd flag definitions.
What does a targeting rule look like?
In flagd's format, this flag is on for beta testers (a reusable list, see segment) and for users on the pro plan, and off for everyone else:
{
"flags": {
"release_new_checkout": {
"state": "ENABLED",
"variants": { "on": true, "off": false },
"defaultVariant": "off",
"targeting": {
"if": [
{ "$ref": "beta_testers" }, "on",
{ "==": [{ "var": "plan" }, "pro"] }, "on",
"off"
]
}
}
},
"$evaluators": {
"beta_testers": { "in": [{ "var": "email" }, ["ana@example.com", "li@example.com"]] }
}
}
We evaluated it with the OpenFeature Node.js SDK and the flagd provider: ana@example.com on the free plan got on (beta tester), bo@example.com on pro got on, and bo@example.com on free got off (flag file, script, output). The context attributes (email, plan) must be passed in by the application; a missing attribute simply doesn't match.
What should I watch out for?
- Attributes come from your code: a rule on
planonly works if every evaluation passesplan, and client-side attributes can be changed by users, so don't use them for access control (entitlements vs feature flags). - Reusable groups: when the same conditions appear on many flags, use a segment.
- Where rules are evaluated: some SDKs download the rules to the device, where users can read them (feature flags in React).
Related
- Testing code that uses feature flags: testing targeting rules with a test provider
- All glossary terms