Functions
| Function | Description | Example |
|---|---|---|
has(x) | Returns true if a trait or address is present on the profile. Use this instead of comparing a possibly missing trait directly to a value. | has(profile.trait.Account.email) |
now() | Returns the current timestamp, evaluated when your snapshot is generated. | profile.trait.Account.lastPurchaseDate < now() |
timestamp(string) | Parses an RFC 3339 timestamp string (for example, timestamp("2026-01-01T00:00:00Z")). Other date formats aren't supported. | profile.trait.Account.lastPurchaseDate > timestamp("2026-01-01T00:00:00Z") |
duration(string) | Parses a Go-style duration string. You can combine units, as in duration("1h30m"). The value must resolve to a whole number of seconds. Sub-second precision (for example, duration("1.5s")) isn't supported. In practice, use h (hours), m (minutes), and s (seconds). | now() - profile.trait.Account.lastPurchaseDate < duration("720h") |
| Function | Description | Example |
|---|---|---|
math.least(a, b, ...) | Returns the smallest of the given values. | math.least(profile.trait.Account.lifetimeValue, 500) |
math.greatest(a, b, ...) | Returns the largest of the given values. | math.greatest(profile.trait.Account.lifetimeValue, 500) |
| Function | Description | Example |
|---|---|---|
string(x) | Converts a value to a string. | string(profile.trait.Account.age) |
int(x) | Converts a value to an integer. | int(profile.trait.Account.lifetimeValue) |
double(x) | Converts a value to a floating-point number. | double(profile.trait.Account.age) |
(information)
Info
Both sides of a comparison must evaluate to the same data type. If you need to compare fields with differing types, such as a numeric string and an integer, use a type conversion function (int(), string(), or double()) to reconcile them. See type matching for the full rules.
Call these as methods on a string value.
| Method | Description | Example |
|---|---|---|
.contains(substring) | Returns true if the string contains substring. | profile.trait.Account.email.contains("@example.com") |
.startsWith(prefix) | Returns true if the string starts with prefix. | profile.trait.Account.email.startsWith("jane") |
.endsWith(suffix) | Returns true if the string ends with suffix. | profile.trait.Account.email.endsWith("@example.com") |
| Operation | Description | Example |
|---|---|---|
size(list) | Returns the number of items in a list. | size(profile.address.email) > 1 |
list.exists(x, condition) | Returns true if at least one item in the list satisfies condition. | profile.address.email.exists(e, e.endsWith("@example.com")) |
list.all(x, condition) | Returns true if every item in the list satisfies condition. | profile.address.phone.all(p, p.startsWith("+1")) |
list.exists_one(x, condition) | Returns true if exactly one item in the list satisfies condition. | profile.address.email.exists_one(e, e == "jane@example.com") |
list.filter(x, condition) | Returns a new list that contains only the items satisfying condition. | profile.address.email.filter(e, e.endsWith("@example.com")) |
Cohorts currently doesn't support list transformation with .map().
- Learn about type matching.
- Review example criteria for common filtering patterns.
- Learn about null handling.