includeProducts Function
#includeProducts iterates through event properties / product objects and displays the corresponding values, based on a range of constrictions you can set within the function. You can for example use this function to release an Abandoned Cart Campaign where you want to display the products within the cart.
#includeProducts also searches in the product feed to return product properties, such as, for example {{[properties.image]}}.
#includeProductsis not limited to fetching product information from the Product Feed only. It can also be used to access and display other types of information, such as event data.
You can choose one of three options which Products to access when using #includeProducts:
- cartProducts
- eventProducts
- stepProducts
Their behaviour is shown in the examples below.
Examples
1. cartProducts.
The cartProducts handlebar is primarily used in cart reminder campaigns. It dynamically displays the items a customer left in their shopping cart, allowing you to create personalized reminders that encourage them to complete their purchase.
The first example is used to access the products in the cart of the user that triggered the campaign.
{{#includeProducts '{
"cartProducts": true,
"options": {
"maxResults": 3,
"sortBy": "properties.price",
"desc": true,
"distinct": true
}
}'
}}
{{[properties.image]}}
{{[properties.title]}}
{{/includeProducts}}
The maxResults option determines how many products will be displayed at most.
The sortBy option determines which product attribute the results will be sorted by.
For sorting order, you can either use desc or asc, both of which are turned on by using "true" as a value.
The distinct option allows you to prevent duplicate entries. You can enable it by using "true" as a value.
If there is no sortBy parameter used, the products will be evaluated in a random order.
More examples:
Use case: product is waiting in the cart and we want to offer the customer accessories items, which are stored in the product feed (Sku) in the Array properties.xaccessories.
Test for Accessories:
{{#includeProducts '{
"cartProducts": true,
"options": {
"maxResults": 2,
"sortBy": "properties.price",
"desc": true,
"distinct": true}
}'}}
Original product SKU: {{[properties.sku]}}
Accessories 1:
{{#findProduct [properties.xaccessories] itemFromList=0}}
Accessories SKU:{{[properties.sku]}},
Productname:{{[properties.title]}},
Image:{{[properties.bigImageLink]}},
Link:{{[properties.link]}}
{{/findProduct}}
Accessories 2:
{{#findProduct [properties.xaccessories] itemFromList=1}}
Accessories SKU:{{[properties.sku]}},
Productname:{{[properties.title]}},
Image:{{[properties.bigImageLink]}},
Link:{{[properties.link]}}
{{/findProduct}}
Combination #cartProducts with #cif
{{#includeProducts '{
"cartProducts": true,
"options": {
"maxResults": 8,
"distinct": true
}}'}}
{{#findProduct [properties.sku]}}
{{#cif '{
"property": "[properties.bigImageLink]",
"operator": "notContains",
"value": "noImage_detail"}'}}
{{[properties.attributes.utmCategory]}}
{{[properties.bigImageLink]}}
{{[properties.title]}}
{{formatDigits '{
"propertyName": "[properties.price]",
"numberDecimals": 2,
"decimalSeparator": ",",
"thousandsSeparator": ".",
"percentage": "false"
}' }} €
{{else}}
{{/cif}}
{{/findProduct}}
{{/includeProducts}}
Combination #cartProducts with #formatDigits
{{#includeProducts '{ "cartProducts": true, "options": { "maxResults": 5, "sortBy": "properties.price", "desc": true, "distinct": true } }' }}{{#findProduct [properties.sku]}}{{[properties.title]}}{{/findProduct}}
{{#findProduct [properties.sku]}}{{formatDigits '{ "propertyName": "[properties.salesPrice]", "numberDecimals": 2, "decimalSeparator": ",", "thousandsSeparator": ".", "percentage": "false" }'}}{{/findProduct}} €
{{#findProduct [properties.sku]}}{{formatDigits '{ "propertyName": "[properties.discount]", "numberDecimals": 0, "percentage": "false" }'}}{{/findProduct}}{{#findProduct [properties.sku]}}{{[properties.attributes.helperDiscountUnit]}}{{/findProduct}}
{{#findProduct [properties.sku]}}{{[properties.attributes.promotionDiscount]}}{{/findProduct}}{{#findProduct [properties.sku]}}{{[properties.attributes.helperPromotionDiscountUnit]}}{{/findProduct}}
{{#findProduct [properties.sku]}}{{[properties.attributes.promotionCode]}}{{/findProduct}}
{{/includeProducts}}
2. eventProducts
This example shows how to access data from an Event that exists in a users' history. This handlebar is most commonly used in Audience Campaigns or Stories. Since ActivatePro stores a users' behaviour as events and attaches them to a user, you can access these events for content personalisation later. We want to access Viewed Product event which happened up to 2 weeks in the past:
{{#includeProducts '{ "eventProducts": { "events": ["Viewed Product"],
"eventTimes": ["-2 weeks","now"],
"operator": "n-th last", "operand": 1}}'}}
{{[properties.title]}}
{{/includeProducts}}
The eventProducts option determines which event in a users' history to access. In this case we are first event of the type "Viewed Product" when going back in time. Another way to phrase this is that we are accessing the "first last Event" or the "first Event from the end".
The events selector determines which Event to look for in a Users' History.
The eventTimes option determines in which timeframe to look for in a Users' History.
-
It always expects two values:
["start", "end"]. - Those values are relative like
["-2 weeks","now"]or["-15 weeks","-14 weeks"] -
It does not support absolute timestamps directly (like
"2025-01-01T00:00:00Z").
The operator for the eventProducts option only accepts "n-th last", which means that you are accessing a specific event, counting from most recent.
The operand determines the value for n in "n-th last", so 2 would mean you are accessing the second to last event in a Users' History. In most scenarios you will want to use 1 here.
-
1 → the most recent (last) event.
-
2 → the second-to-last event.
-
3 → the third-to-last event, and so on.
Example - If you set the operand to 2, you’ll retrieve the property value from the event before the last one in the User’s History.
Examples:
Use case:
We need to retrieve data from the event named “Event with property”. The requirement is to fetch data only for a one-week period, specifically between 14 and 15 weeks ago. From this timeframe, we want to identify the most recent occurrence of the event and extract the height property from it.
{{#includeProducts '{"eventProducts": {
"events": ["Event with property"],
"eventTimes": ["-15 weeks","-14 weeks"],
"operator": "n-th last",
"operand": 1}}
'}}
{{[properties.height]}}
{{/includeProducts}}
Use case: If an event contains a property "properties.deliverydate" with a datetime value, and we need to both retrieve this property and reformat the datetime into a different format, we can achieve this by combining the #includeProducts and #computeDate handlebars.
{{#includeProducts '{"eventProducts": { "events": ["Event with property"],
"eventTimes": ["-2 weeks","now"],
"operator": "n-th last", "operand": 1}}'}}
{{computeDate '{"dateTrait": "[properties.deliverydate]","outputFormat": "dd.MM.yyyy"}'}}
{{/includeProducts}}
3. IncludeProducts within journey steps
The name of the handlebar #stepProducts can be misleading – it is not fetching products, but actually retrieving properties from the event in the real-time campaign journey steps.
For example, a campaign may start with an Added Product event. After a waiting time of 3 hours, we might want to send a message using the data from that initial Added Product event. In this case, #stepProducts pulls the properties from the start event, not from the product catalog.
{{#includeProducts '{"stepProducts": [0]}'}}
title: {{[properties.title]}}
price: {{[properties.price]}}
{{/includeProducts}}