conversionloopdevelopers

Audience rules

An audience decides who sees a campaign. Its rules are evaluated in the visitor's browser, so nothing about the visitor is sent before a campaign shows. Rules that depend on behaviour, such as scroll depth or exit intent, are checked again while the visitor is on the page.

Structure

Rules consist of groups of conditions:

{
  "groups": [
    {
      "id": "where",
      "match": "any",
      "conditions": [
        { "id": "c1", "type": "url", "operator": "contains", "value": "/checkout" },
        { "id": "c2", "type": "url", "operator": "contains", "value": "/cart" }
      ]
    },
    {
      "id": "when",
      "match": "all",
      "conditions": [
        { "id": "c3", "type": "exit_intent", "operator": "is_true" },
        { "id": "c4", "type": "data_field", "field": "cart_value", "operator": "gte", "value": 50 }
      ]
    }
  ]
}

This audience matches visitors on the checkout or the cart, and who are about to leave and have at least 50 in their cart.

  • match: "all": every condition in the group must match (AND).
  • match: "any": one condition in the group is enough (OR).
  • Groups are always combined with AND: a visitor must match every group.
  • Up to 10 groups with up to 30 conditions each.
  • ids are yours to choose. They only need to be unique within the audience.

Excluding visitors

Set "include": false to turn a condition around. Visitors who match it are excluded:

{ "id": "c5", "type": "campaign_state", "field": "checkout-exit", "operator": "eq", "value": "answered", "include": false }

Building on other audiences

The audience condition uses another saved audience. That lets you keep common segments in one place, such as "returning customers" or "mobile visitors from paid campaigns":

{ "id": "c6", "type": "audience", "operator": "in", "value": "aud_2m8k4x9q1v7b3n6c5z0wd" }

The API checks the references when you save: an audience that does not exist, or one that would refer back to itself, is rejected with 422.

Operators

Each condition type allows only some operators; the table further down lists them.

operatorMeaning
eqequals
neqdoes not equal
gtgreater than
gtegreater than or equal
ltless than
lteless than or equal
betweenbetween two values (inclusive), given as [min, max]
containscontains the text
not_containsdoes not contain the text
starts_withstarts with the text
ends_withends with the text
regexmatches the regular expression (JavaScript syntax)
inis one of the listed values
not_inis none of the listed values
existsis present
not_existsis not present
is_trueis true
is_falseis false

Conditions

Conditions marked live are re-evaluated while the visitor is on the page. All others are checked when the page loads, after conversionloop.set() and after conversionloop.refresh().

Behaviour

typeChecksoperatorvalue
dwell_time
live
Active time on the current page. Time in a background tab or without interaction does not count. gt gte lt lte between Milliseconds, e.g. 30000.
scroll_depth
live
Deepest point the visitor scrolled to on the current page. gte lt between Percent of the page height, 0–100.
exit_intent
live
The visitor is about to leave: the pointer leaves the window towards the top (desktop), or a fast scroll up (mobile). is_true None.
page_views
live
Pages viewed in the current session. eq gt gte lt Number.
visit_count Number of separate visits, remembered on the visitor's device. 1 is the first visit. eq gt gte lt Number.
element_seen
live
An element was visible on screen for at least the given time.
field: CSS selector, e.g. #pricing.
gte Milliseconds.
click
live
The visitor clicked an element during the session.
field: CSS selector, e.g. .add-to-cart.
exists None.
inactivity
live
No mouse, keyboard, touch or scroll activity for at least the given time. gte Milliseconds.

Page and visit

typeChecksoperatorvalue
url Full URL of the current page, including query string. eq neq contains not_contains starts_with ends_with regex Text, or a regular expression for regex.
referrer URL of the page the visitor came from. eq contains regex exists not_exists Text, or a regular expression for regex.
utm A UTM parameter of the visit. Taken from the landing page, so it stays available on later pages.
field: Parameter name, e.g. utm_source.
eq contains exists not_exists Text.
landing_page URL of the first page of the visit. eq contains starts_with regex Text, or a regular expression for regex.
schedule Date, weekday and time of day. between Object with any of from, to (ISO dates), weekdays (0 = Sunday … 6 = Saturday), timeFrom, timeTo (HH:MM) and timezone (visitor or workspace).

Browser and device

typeChecksoperatorvalue
device_type Device class, from screen size and user agent. eq neq in not_in One of the options, or a list for in/not_in.
phone tablet desktop
browser Browser family. eq neq in not_in One of the options, or a list for in/not_in.
chrome safari firefox edge opera samsung other
os Operating system. eq neq in not_in One of the options, or a list for in/not_in.
windows macos ios android linux other
viewport
live
Width of the browser window in CSS pixels. Re-checked when the window is resized. gt gte lt lte between Number, or two numbers for between.
language Preferred language of the browser. eq starts_with in Language tag, e.g. de or de-AT; a list for in.
connection Connection quality reported by the browser. Only available in browsers with the Network Information API. eq in One of the options, or a list for in.
slow-2g 2g 3g 4g save-data
prefers_reduced_motion The visitor asked their system for less motion. is_true is_false None.
storage A value in localStorage or sessionStorage.
field: localStorage:key or sessionStorage:key.
exists not_exists eq contains Text; none for exists/not_exists.

Your own data

typeChecksoperatorvalue
data_field A data field your page set with conversionloop.set(). Re-checked whenever you set new values.
field: Key of the data field.
eq neq gt gte lt lte contains in not_in exists not_exists Text, number or boolean matching the field type; a list for in/not_in.
campaign_state What the visitor did with another campaign.
field: Slug of the other campaign.
eq One of the options.
seen answered dismissed not_seen not_answered
audience Membership in another saved audience. Lets you build on existing segments. Loops are rejected when saving. in not_in ID of the other audience (aud_…). not_in excludes its members.

Validation

When you create or change an audience, the API rejects rules with 400 and lists the issues in details when:

  • an operator is not allowed for the condition type,
  • a type that needs a field has none,
  • an operator that needs a value has none, or between gets no [min, max] pair,
  • a value is not one of the allowed options,
  • a regular expression does not compile.