Targeting rules
Targeting rules let you serve different flag values to different users based on their attributes. Each flag can have zero or more rules.
Rules are evaluated in sequential order, from top to bottom. The first rule whose conditions match is used, and its configured variant is returned. If no rule matches, Flagship returns the flag's default variant.
When a flag is disabled, the default variant is always returned regardless of rules.
Place more specific rules before broader rules. A broad catch-all rule can prevent later rules from running.
A rule consists of:
- Conditions — One or more attribute comparisons that must be satisfied. For example,
country equals "US"orplan in ["enterprise", "business"]. - Serve variant — The variant to return when the rule matches.
- Rollout (optional) — A percentage-based gradual release. Only the specified percentage of matching users receive the rule's variant. The rest continue to the next rule.
Each condition compares an attribute from the evaluation context against a value using an operator:
- Attribute — The context key to evaluate (for example,
userId,country,plan). - Operator — The comparison to perform. Flagship supports 11 operators.
- Value — The value to compare against. Can be a string, number, or array depending on the operator.
If the evaluation context does not include the attribute referenced by a condition, that condition does not match.
Conditions within a rule can be grouped with AND/OR operators and nested up to five levels deep.
For example, to target enterprise users in the US or Canada:
AND:plan equals "enterprise"OR:country equals "US"country equals "CA"
Use the smallest set of context attributes necessary to express the rule. This keeps rule behavior easier to reason about and avoids sending unnecessary user data in evaluation context.