Skip to main content

Conditions and filtering

To make match more nuanced, you can add an if clause to it with conditions on tags defined in the match pattern and on sequence dimensions, for example:

// Match US purchases above $100
set country = SEQ[0].country
match purchase
if (purchase.price > 100) and (country = 'US')

To define “strict” funnels, you can use nested() function in the if clause:

match Step1(search) >> * >> Step2(add_to_cart)? >> * >> Step3(checkout)?
// Only match 'checkout' if 'add_to_cart' was matched
if nested(Step2, Step3)

It is very common to work with time and duration conditions, so Sequence Operations Language (SOL) supports special time literals and time/duration functions:

match search_page >> * >> purchase
// Only match 2023 purchases, which took less than 30 minutes to complete after visiting "search_page"
if (purchase.ts > '2023-01-01') and (duration(search_page, purchase) < 30min)
// Define user cohort based on the week the purchase was made
set user_cohort = time_bucket(1w, purchase.ts)

SOL supports the ISO string and Linux epoch integer time formats. Motif automatically recognizes them in the loaded data and converts to microseconds for internal storage. This standardization allows Motif to support user-friendly duration literals like 30min and 5.5h. You can find all time and duration functions in the SOL functions reference.

To more tightly control how match boundaries are defined, you can use look-ahead/behind conditions by referencing PREFIX and SUFFIX tags inside the if clause:

// Find abandoned carts: no "checkout" within 1 hour of adding items to the cart
match add_to_cart >> (^checkout)*
// Only match if the next event after the matched pattern is at least 1 hour after "add_to_cart" (or there are no events after the match in the sequence)
if duration(add_to_cart, SUFFIX[0]) > 1h

match only assigns tags in the matched patterns, but doesn’t filter out sequences without matches. To remove them, SOL provides the filter operation.

filter gif

It uses the same types of conditions as the if clause, for example:

match purchase
set country = SEQ[0].country
// Filter to sequences with matches - they have an implicit 'MATCHED' tag
filter MATCHED
// Filter to US sequences with purchases over $100
filter (purchase.price > 100) and (country = 'US')