Targeting Rules
Control which users see a feature based on their attributes. Define rules in the dashboard, send the user's attributes from your app, and Abrova Flags decides who gets the flag.
Targeting rules let you control which users see a feature based on their attributes. You define the rules in the dashboard and your app only says who the user is. Rules are never sent to apps or browsers.
How Targeting Works#
When you create a flag, you can define targeting rules as conditions on user attributes. The rules are checked against the context of the user: the user id, the anonymous id and the attributes you provide.
The SDK sends the context to Abrova Flags, which checks the rules and returns the values for this user. A change of attributes fetches new values
The SDK downloads the rules with the server secret and checks them locally against the context you pass with each call
Conditions are combined in a group with AND (all must match) or OR (at least one must match). If no targeting rules are defined, the flag applies to all users. A user who does not match gets the flag's off value with reason NOT_TARGETED.
Setting User Attributes#
Pass user attributes to the SDK so targeting rules can evaluate against them:
Client-Side SDKs
// React Native / Next.js (client)
await flags.identify('user-123', {
plan: 'pro',
country: 'US',
age: 28,
email: 'user@company.com',
});
// Later: replace the whole set of attributes
await flags.setAttributes({ plan: 'business', country: 'US' });// Flutter
await flags.identify('user-123', attributes: {'plan': 'pro', 'country': 'US'});// Android
flags.identify("user-123", mapOf("plan" to "pro", "country" to "US"))// iOS
flags.identify("user-123", attributes: ["plan": "pro", "country": "US"])identify with attributes and setAttributes replace the whole set. Send every attribute your rules need each time. An attribute you leave out no longer exists for the rules.
Server-Side SDKs
// Node.js / Next.js (server) — pass context per evaluation
const isEnabled = flags.isEnabled('premium_feature', {
userId: 'user-123',
attributes: {
plan: 'pro',
country: 'US',
},
});What an attribute can be
| Limit | Value |
|---|---|
| Value types | String, number, boolean, null, or an array of those. No nested objects |
| Number of attributes | At most 100 |
| Attribute name | 1 to 100 characters |
| String value | At most 1,024 characters |
| Array | At most 100 items |
| userId and anonymousId | Not attributes. Rules on userId or anonymousId read the id of the context, and an attribute with one of these names is ignored |
Attributes are sent to Abrova Flags with each fetch. Send what your rules need, and avoid personal data you do not target on.
Comparison Operators#
Targeting rules support these operators:
| Operator | Value | Matches when |
|---|---|---|
| equals | any | The attribute equals the value |
| not_equals | any | The attribute does not equal the value |
| in | array | The attribute is one of the values |
| not_in | array | The attribute is none of the values |
| contains | string | The attribute is a string that contains the value |
| not_contains | string | The attribute does not contain the value |
| starts_with | string | The attribute is a string that starts with the value |
| ends_with | string | The attribute is a string that ends with the value |
| regex | string | The attribute is a string and the pattern matches somewhere in it |
| greater_than | number | Attribute > value |
| less_than | number | Attribute < value |
| greater_than_or_equal | number | Attribute >= value |
| less_than_or_equal | number | Attribute <= value |
| exists | boolean | true: the attribute is present and not null. false: it is missing or null |
| in_segment | segment | The user matches the segment |
| not_in_segment | segment | The user does not match the segment |
The rule builder in Abrova Console offers is, is not, is one of, is not one of, contains, greater than, less than, matches regex, exists, doesn't exist, is in segment and is not in segment.
How values are compared
- Text comparison is case-sensitive:
Prodoes not equalpro. - A number and a numeric string are equal when the numbers are equal:
28equals"28". The number operators also accept numeric strings. - A boolean equals the strings
"true"and"false". - If the attribute is an array, a condition matches when any item matches. For example
tags: ['beta', 'staff']matchestags equals beta. - If the attribute is missing,
equals,in,containsand the other positive operators do not match, andnot_equals,not_in,not_containsandnot_in_segmentdo match. regexlooks for the pattern anywhere in the value. Use^and$to match the whole value.
Rule Examples#
A rule set is a group with an operator and a list of conditions. You build it in the dashboard; this is the shape the server SDKs receive:
{
"operator": "AND",
"rules": [
{ "attribute": "country", "operator": "in", "value": ["US", "CA", "UK"] },
{ "attribute": "plan", "operator": "equals", "value": "premium" }
]
}Here are common patterns:
Country Targeting
{ "attribute": "country", "operator": "in", "value": ["US", "CA", "UK"] }Plan-Based Access
{ "attribute": "plan", "operator": "equals", "value": "premium" }Email Domain Targeting
{ "attribute": "email", "operator": "regex", "value": "@company\\.com$" }Combined Rules (AND Logic)
{
"operator": "AND",
"rules": [
{ "attribute": "country", "operator": "in", "value": ["US", "CA"] },
{ "attribute": "plan", "operator": "equals", "value": "premium" },
{ "attribute": "age", "operator": "greater_than_or_equal", "value": 18 }
]
}All three conditions must be true for the flag to be enabled for this user.
Either Condition (OR Logic)
{
"operator": "OR",
"rules": [
{ "attribute": "plan", "operator": "equals", "value": "enterprise" },
{ "attribute": "segment", "operator": "in_segment", "value": "beta-testers" }
]
}A segment is a saved group of users defined by its own attribute conditions. The flag is enabled for enterprise users and for everyone in the beta-testers segment.
Targeting and Rollouts Together#
Targeting is checked before the rollout percentage. With rules for plan equals premium and a rollout of 20%, the flag is on for 20% of premium users and off for everyone else. See Percentage Rollouts and the Evaluation Flow.
Read the reason of the flag with getDetail. NOT_TARGETED means the rules did not match the attributes that were sent. Check the spelling and the type of each attribute, and remember that setAttributes replaces all of them.