Skip to main content
Segments, triggers and 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.
A segment filter can only use customer. variables. A segment whose filter uses any other variable matches no customers.

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_at doesn’t match Date.now() - Date(customer.last_check_in_at) > 2592000. The exception is in with a missing list: "vip" in customer.tags is neither true nor false for a customer without tags, so !("vip" in customer.tags) doesn’t match them either.
  • In a trigger filter or if step, the whole filter is false, even if another part of an || would match. Every part of the filter is checked, so has() can’t guard a comparison: when a value can be missing, sync a default for it, such as "visits": 0.
So that “don’t have a tag” filters match customers with no tags, sync an empty list for them, such as "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.