Rule-Based Segments#

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 true/false in context of a User profile which is associated with a set of Attributes.
  • Segments can then be used in Activations to selectively activate users.

Segment Creation#

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.


Segment Rules Syntax#

A rule is a string that represents a boolean expression. It should be in the format <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:

Boolean operatorMeaningExample
=, ==, isequal tocountry = "US"
<, ltless thanage < 50
>, gtgreater thanage > 20
<=less than or equalage <= 50
>=greater than or equalage >= 20
inpresent in list of itemscountry in ("US", "FR")
inRangepresent in range of valuesage inRange (20, 50)
!, notboolean "not"!(country = "US")
|, ||, orboolean "or"country = "US" or age < 50
&, &&, andboolean "and"age > 20 & age < 50
containsstring containsuser-agent contains "Chrome"
startsWithstring startsWithuser-agent startsWith "Chrome"
endsWithstring endsWithuser-agent endsWith "81"
containsAnyarray contains any elementsids containsAll (1, 2, 3)
containsAllarray contains all elementsids containsAny (1, 2, 3)
Geo OperatorMeaningExample
near byvalue near coordinateuserCoordinates near (41.176296, -8.596050) by 30 km
Date OperatorMeaningExample
aftertimestamp is after x dayslastPurchase after 7 days ago
beforetimestamp is before x dayslastPurchase before 3 days ago
betweentimestamp is between x and y dayslastPurchase between 3 and 7 days ago
oneOfgroup of boolean "or"soneOf(country = "US", age < 50)
allOfgroup of boolean "and"sandOf(age > 20, age < 50)
isDefinedreturns true if a variable is definedisDefined(country)
existsfirst-order "or" operatorexists(c:countries, c == "US")
forAllfirst-order "and" operatorforAll(p:purchases, p > 50)

We also have support for programmatically create your own complex rules. For more information see the API Reference.

Last updated on