Targeting Rules
Targeting rules define which users see your content. Rules are organized into a tree structure of groups and conditions, evaluated by the targeting engine at runtime.
Rule Tree Structure
A rule tree consists of rule groups and rule nodes:
- Rule group -- a container with a logical operator (
ANDorOR) and one or more child rules or nested groups. - Rule node -- a leaf condition that compares a single user attribute against a value using a comparison operator.
Groups can be nested to express complex logic. An empty group evaluates to true.
AND Group
├── role eq "admin"
├── OR Group
│ ├── country in ["US", "CA"]
│ └── plan eq "enterprise"
└── loginCount gte 5
In this example, the user must be an admin and have logged in at least 5 times and be located in the US/CA or on an enterprise plan.
Comparison Operators
The targeting engine supports 15 comparison operators:
| Operator | Name | Description | Accepted Types |
|---|---|---|---|
eq | Equals | Strict equality | Any |
neq | Not equals | Strict inequality | Any |
gt | Greater than | Field is greater than value | Number |
lt | Less than | Field is less than value | Number |
gte | Greater than or equal | Field is greater than or equal to value | Number |
lte | Less than or equal | Field is less than or equal to value | Number |
contains | Contains | String includes substring (case-insensitive), or array includes element | String, Array |
not_contains | Does not contain | Inverse of contains | String, Array |
in | In array | Field value exists in the provided array | Any (rule value must be Array) |
not_in | Not in array | Field value does not exist in the provided array | Any (rule value must be Array) |
exists | Exists | Field is not undefined or null | Any |
not_exists | Does not exist | Field is undefined or null | Any |
regex | Regex match | Field matches a regular expression | String |
starts_with | Starts with | Field begins with the given prefix (case-sensitive) | String |
ends_with | Ends with | Field ends with the given suffix (case-sensitive) | String |
Type Coercion Behavior
The evaluator uses strict typing with no implicit coercion:
- Numeric operators (
gt,lt,gte,lte) returnfalseif either the field value or rule value is not anumber. - String operators (
contains,regex,starts_with,ends_with) returnfalseif either operand is not astring. containsandnot_containson strings use case-insensitive comparison. On arrays, string elements are compared case-insensitively while non-string elements use strict equality.
Client-Side Evaluation
The SDK evaluates targeting rules locally using the user context passed during initialization. The context object includes attributes such as userId, email, role, custom properties, and page URL. Rules are downloaded once on SDK initialization and re-evaluated when the user context changes.
Priority When Multiple Audiences Match
When a user matches more than one audience, content delivery follows these rules:
- Explicit priority -- audiences with a higher priority value take precedence.
- Specificity -- audiences with more matching rules are preferred when priorities are equal.
- First match -- if priority and specificity are identical, the first audience in creation order wins.
Only one variant of a given content item is shown to a user at any time.