Segments allow creating groups of users that match a given rule. A Segment Rule acts on users' attributes as variables combined with operators and values, enabling the implementation of full boolean-logic expressions. User Attributes can be created using enrichments from collected events, onboarded from CRM systems, or provided by third parties.
How do segments interact with the rest of the system?
- A segment is evaluated to
falsein context of a User profile which is associated with a set of Attributes.
- Segments can then be used in Activations to selectively activate users.
For most of the rules we recommend using the dashboard segment builder as it provides a way to easily create complex rules visually.
In addition to a powerful segment editor, we also offer insights on what the ID reach will be for the currently being edited rule and helpers for selecting the best value for our machine-learning based attributes.
A rule is a string that represents a boolean expression. It should be in
<variable> <operator> <value>. Additionally, rules can be combined in the following format
<rule> <boolean operator> <rule>. Quotes inside the rules need to be escaped appropriately.
The following operators are supported:
|=, ==, is||equal to||country = "US"|
|<, lt||less than||age < 50|
|>, gt||greater than||age > 20|
|<=||less than or equal||age <= 50|
|>=||greater than or equal||age >= 20|
|in||present in list of items||country in ("US", "FR")|
|inRange||present in range of values||age inRange (20, 50)|
|!, not||boolean "not"||!(country = "US")|
||, ||, or||boolean "or"||country = "US" or age < 50|
|&, &&, and||boolean "and"||age > 20 & age < 50|
|contains||string contains||user-agent contains "Chrome"|
|startsWith||string startsWith||user-agent startsWith "Chrome"|
|endsWith||string endsWith||user-agent endsWith "81"|
|containsAny||array contains any elements||ids containsAll (1, 2, 3)|
|containsAll||array contains all elements||ids containsAny (1, 2, 3)|
|near by||value near coordinate||userCoordinates near (41.176296, -8.596050) by 30 km|
|after||timestamp is after x days||lastPurchase after 7 days ago|
|before||timestamp is before x days||lastPurchase before 3 days ago|
|between||timestamp is between x and y days||lastPurchase between 3 and 7 days ago|
|oneOf||group of boolean "or"s||oneOf(country = "US", age < 50)|
|allOf||group of boolean "and"s||andOf(age > 20, age < 50)|
|isDefined||returns true if a variable is defined||isDefined(country)|
|exists||first-order "or" operator||exists(c:countries, c == "US")|
|forAll||first-order "and" operator||forAll(p:purchases, p > 50)|
We also have support for programmatically create your own complex rules. For more information see the API Reference.