How to work with Expressions

What Are Expressions?

An expression is a string with a specific syntax. It is “executed” on the server within a particular context, and the result of the execution is one of two boolean values: true or false.

Essentially, an expression answers the question: should this specific email be sent to this specific subscriber right now?

For trigger emails, such questions usually do not arise — they are always sent. Marketing emails are more complex. Whether an email should be sent depends on what data is available for the subscriber (for example, an email with gift ideas for March 8 makes more sense for a male audience than for a female one), which emails the subscriber has received before, and how they interacted with them.

All of these complex rules (business logic) can be expressed as a sequence of checks and comparisons. Executing them leads to a “Yes” or “No” answer — the already mentioned boolean value true / false.

In our system, such Expressions are available in several places and may have different sets of variables that can be referenced within an expression.

Basic Syntax

Inside an expression, you can use different data types:

  • 10 — integer
  • 3.14 — floating-point number
  • true — boolean value true
  • false — boolean value false
  • null — special value null
  • "Hello" — string
  • subscriber.id — access to an object property
  • "World" — another way to define a string
  • ["new", "paid", "shipped"] — array of strings

Comparison operators

  • == — equal to
  • != — not equal to
  • < — less than
  • <= — less than or equal to
  • > — greater than
  • >= — greater than or equal to

Mathematical operators

  • + — addition
  • - — subtraction
  • * — multiplication
  • / — division

Logical operators

  • AND — logical AND
  • OR — logical OR
  • NOT — logical NOT

You can also use parentheses to change the order of evaluation, as in mathematical formulas: expressions inside parentheses are evaluated first.

Some Examples

subscriber.address_country in ["UA", "PL", "NL"] — returns true only if the subscriber’s country is one of the three listed.

(subscriber.birthday_month == now.format("M")) AND (now.format("Y") - subscriber.birthday_year == 18) — the subscriber has a birthday this month and is turning 18.

Available Variables

The set of available variables depends on where the Expression is used.

Variables available for the condition to enter a subscriber campaign:

time, subscriber, tags, now

Variables available for checking Event execution in a campaign:

time, subscriber, tags, now, url (only for link click events), url_md5 (only for link click events)

Variable Descriptions

  • time — an integer representing the current time in Unix timestamp format
  • subscriber — an object containing subscriber data; a detailed description of its fields is available on this page
  • tags — an array of strings containing subscriber tags, for example ["tag1", "tag2", "tag3"]
  • now — a special object representing the current time with a format method. For example, now.format("Y") returns the current year as a string (4 characters)
  • url — contains the HTTP link that was clicked
  • url_md5 — contains the MD5 string, i.e. the MD5 value of the clicked link