Using Expressions

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.


🧩 What Are Member Custom Attributes?

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.


✅ Supported Data Types

Custom attributes support the following value types:

Type
Example

DateTime

"2022-12-20T14:15:22+01:00"

Number

"10.2"

String

"featured"


🛠️ How to Use Custom Attributes in Expressions

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:

1. Retrieve a Label Value

agg(customer.labels).getFirstLabelValue('post_date')

Returns the value of the label post_date as a string.

2. Parse a Label to a Date

to_date(agg(customer.labels).getFirstLabelValue('post_date'))

Converts the string to a date format for further operations.

3. Compare with a Timestamp

timestamp(to_date(agg(customer.labels).getFirstLabelValue('post_date')))

Converts the value to a UNIX timestamp for time-based comparisons.


📌 Real Example: Reward Within 5 Days of a Custom Date

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

🔢 Comparing Numeric Custom Attributes

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

✨ Combine with Other Expressions

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:

Expressions

🔍 Summary

Using 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.

Last updated

Was this helpful?