Skip to contentSkip to navigationSkip to topbar
Page tools
Useful for sharing or LLM
Accelerate development with AI

On this page
Looking for more inspiration?Visit the

Functions


Presence and time

presence-and-time page anchor
FunctionDescriptionExample
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.timestamp(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. Only millisecond precision is kept (see timestamp precision and format). Use it to convert a trait that stores a date as a string.timestamp(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 argument must be a string literal rather than a trait, and it 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() - timestamp(profile.trait.Account.lastPurchaseDate) < duration("720h")

FunctionDescriptionExample
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)

FunctionDescriptionExample
string(x)Converts a value to a string. A double keeps its decimal point, so string(1.0) returns "1.0". See converting numbers to strings.string(profile.trait.Account.age)
int(x)Converts a value to an integer. Truncates decimals toward zero instead of rounding, so int(2.7) returns 2.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.

MethodDescriptionExample
.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")

OperationDescriptionExample
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"))

The size() function also accepts a string and returns its length, as in size(profile.trait.Account.name) > 3.

Cohorts currently doesn't support list transformation with .map(), regular expressions with matches(), math.abs(), or map literals such as {"a": 1}.


  • Learn about type matching.
  • Review example criteria for common filtering patterns.
  • Learn about null handling.