if steps take a filter: an expression that is true for the customers it
should match. The segment and trigger editors in the embed write these expressions for you. Write
them yourself when you create segments or triggers through the API, as in
Build segments and triggers with the API.
Variables
Use dots for nested keys:
customer.address.city reads metadata.address.city. Names are
case-sensitive, so customer.Plan and customer.plan are different keys.
Values
Sync numbers as JSON numbers, not strings:
"visits": 12 rather than "visits": "12". A number
stored as a string doesn’t compare reliably with > or <.
Operators
From loosest to tightest binding:
Use parentheses to group:
(customer.plan == "gold" || customer.plan == "silver") && customer.vip == true.
Division isn’t supported, and and, or and not aren’t keywords.
Functions
Subtracting one date from another gives the difference in seconds. Dates are compared in UTC.
Examples
Common durations in seconds: 1 day is
86400, 7 days is 604800, 30 days is 2592000, and 90 days
is 7776000.
Missing values
== null and != null are true or false as you’d expect for a missing value. Any other comparison
or arithmetic with a missing value doesn’t match:
- In a segment, that comparison is false and the rest of the filter is still checked. A customer
without
last_check_in_atdoesn’t matchDate.now() - Date(customer.last_check_in_at) > 2592000. The exception isinwith a missing list:"vip" in customer.tagsis neither true nor false for a customer withouttags, so!("vip" in customer.tags)doesn’t match them either. - In a trigger filter or
ifstep, the whole filter is false, even if another part of an||would match. Every part of the filter is checked, sohas()can’t guard a comparison: when a value can be missing, sync a default for it, such as"visits": 0.
"tags": [], rather than leaving the key out.
Writing filters
- Separate tokens with spaces. Write the filter on a single line, without tabs or line breaks, and use double quotes for strings.
- Pocketflows checks that a filter parses when you save it, but not that the variables it uses exist. A misspelled key makes the filter match no one.