Using Expressions
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
Expressions in Open Loyalty campaigns allow you to build flexible and dynamic logic for controlling when effects are applied. One of the most powerful features is the ability to reference custom attributes of members to tailor campaign behavior based on specific data stored in their profiles.
Member custom attributes—also referred to as labels—are member-specific fields used to store additional information. These can be dates, numbers, or strings, such as:
post_date
– a custom date stored for a member
posts_number
– a count of submitted posts
membership_level
– a string indicating tier
You can reference these values inside expressions using Open Loyalty’s expression syntax.
Custom attributes support the following value types:
DateTime
"2022-12-20T14:15:22+01:00"
Number
"10.2"
String
"featured"
To retrieve and use custom attribute values inside campaign rules, you can use the agg(customer.labels).getFirstLabelValue('key')
function. Here's how to apply this in practice:
agg(customer.labels).getFirstLabelValue('post_date')
Returns the value of the label post_date
as a string.
to_date(agg(customer.labels).getFirstLabelValue('post_date'))
Converts the string to a date format for further operations.
timestamp(to_date(agg(customer.labels).getFirstLabelValue('post_date')))
Converts the value to a UNIX timestamp for time-based comparisons.
If you want to grant points only if the transaction happened within 5 days of a custom date, you can use the following condition:
(timestamp(transaction.purchasedAt) - timestamp(to_date(agg(customer.labels).getFirstLabelValue('post_date')))) <= 432000
Important: To ensure the campaign only runs if the attribute is present, always include a null-check condition:
agg(customer.labels).getFirstLabelValue('post_date') != null
When comparing numeric values stored as custom attributes, you do not need additional parsing—just ensure you use a dot (.) separator for decimals:
agg(customer.labels).getFirstLabelValue('posts_number') > 10
Custom attributes can be used in combination with other expression elements such as:
transaction.sku
customer.getWallet().activeUnits
transactionItemFilters
campaignContext
To learn more about general expression syntax, supported operators, and context, visit:
ExpressionsUsing custom attributes in campaign expressions allows you to:
Personalize reward logic
Set campaign conditions based on member behavior
Handle complex use cases like anniversary dates, member segmentation, or activity limits
Whether you're working with dates, numbers, or string attributes, Open Loyalty's expression engine helps you build sophisticated rules for smarter, more contextual campaigns.