Links

Product helper functions

Fetch a product from the product feed

Explanation
#findProduct fetches a product from your Product Feed, by using an SKU. By itself, it's a limited function, but when used in conjunction with #includeProducts or #findMatching, it can be a powerful tool for customizing your messages.

Examples

Find a Product by its SKU

The first example shows how to use the #findProduct function to fetch the image link of a users' favourite Product, which has been attached to the User via the User Feed.
{{#findProduct user.[traits.favoriteProductSku]}}
{{[properties.image]}}
{{/findProduct}}

Get the remaining Stock Count for products in the Cart

The second example shows how to use the #findProduct function together with #includeProducts to show the remaining stock for the three most expensive items in the cart.
{{#includeProducts '{
"cartProducts": true,
"options": {
"maxResults": 3,
"sortBy": "properties.price",
"desc": true,
"distinct": true
}
}'
}}
{{#findProduct [properties.sku]}}
{{[properties.stockRemaining]}}
{{/findProduct}}
{{/includeProducts}}

#findProduct extension to search a list (also within another product)

On June 7, we've included an update to our #findProduct function that can enable you to go even further than before by pulling a specific element from a list (or even a list attached to another product). Here's what the list could look like in the product feed:
{
mainProductSKU: 111111,
accessoriesSKUS: 998776, 776655, 223344, 778899
}
This works great with simple cross-selling cases, especially when you'd like your customer to buy accessories for an item or even other related items. Here's an example of how to search within another product:
{{#findProduct [properties.sku]}} <!-- this searches for the main product -->
{{#findProduct [properties.accessoriesSKUS] itemFromList=0}} <!--this searches within the main product for the first item in the list-->
{{[properties.name]}}
{{[product.price]}}
{{/findProduct}}
{{/findProduct}}
The above example will search the "mainProductSKU" (111111 in our example) and returns the details of the first accessory (itemFromList=0 in our example, which is 998776).

Fetch a product from a journey step

#forEachProductInJourney is a HandleBars helper function for realtime campaigns which can be used to iterate through the cart object sent within events. You can use it to display and filter products in the cart. For example, you can use this helper function to set up an Abandoned Cart Campaign.
Before using the helper function, it's important to ensure that the events used have the right structure. If these do not contain the cart object, the helper function will not work. For ease of setup, please see the example event below containing the cart object:
{
"externalId": "31764034000",
"events": [{
"properties": {
"orderId": "50314b8e9bcf000000000000",
"cart": {
"total": 500.00,
"currency": "EUR",
"products": [
{
"id": "507f1f77bcf86cd799439011",
"sku": "975229855",
"name": "Item 1",
"price": 200,
"quantity": 1,
"colour": "red",
"hasAccessories": false
},
{
"id": "507f1f77bcf86cd799439011",
"sku": "975229856",
"name": "Item 2",
"price": 200,
"quantity": 1,
"colour": "blue",
"hasAccessories": true
},
{
"id": "507f1f77bcf86cd799439011",
"sku": "975229857",
"name": "Item 3",
"price": 20,
"quantity": 1,
"colour": "blue",
"hasAccessories": false
}
]
}
},
"event": "Completed Order"
}]
}
Now that the events are set up correctly, we can target them with the HandleBars function. For our example, we assume that we have a single-step user journey that uses the Completed Order event as the campaign trigger. We set up the helper function so that it will only return 3 products with unique colours with a price over 50 EUR sorted by price (descending):
{{#forEachProductInJourney '{
"JourneyStep": [0],
"options": {
"maxResults": 3,
"sortBy": "price",
"desc": true,
"distinctBy": "colour",
"filters": [
{"property": "price",
"operator": ">",
"value": "50"}
]
}
}'}}
{{name}}
{{quantity}}
{{price}}
{{/forEachProductInJourney}}
JourneyStep represents the journey step used for the event data extraction (0 is the first step of a journey)
The options object allows you to apply filters to your selection (optional):
  • maxResults lets you set the maximum number of results the function will return
  • sortBy lets you select the property which will be used to sort the results. You can select any cart property you'd like as the function can sort both alphabetically and numerically
  • desc lets you set whether the function should return the results descending. "desc": false will enable ascending sorting. Results will be sorted based on the value used in the sortBy field
  • distinctBy lets you select what cart property you'd like to use to distinguish returned products by. In our example, we only return products that have unique colours
  • filters is an array that allows you to add filters to the returned products. In the example above, we filter products that only have a price over 50 EUR. Please use the operators below when setting up the filters

Fetch a product from a tracking event

Explanation
#includeProducts iterates through product objects and displays the corresponding products, based on a range of constrictions you can set within the function. You can for example use this function to realise an Abandoned Cart Campaign where you want to display the products within the cart.
#includeProducts also searches the product feed to return product properties, such as, for example {{[properties.image]}}.
You can choose one of three options which Products to access when using #includeProducts:
  • cartProducts
  • eventProducts
Their behaviour is shown in the examples below.
Examples
Products in the Users' Cart
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]}}
{{/includeProducts}}
The cartProducts selector accepts True or False. If it is set to True, the #includeProducts function will access the cart object that can be sent in the Webtracking.
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.
Products in a Users' History
The last example shows how to access data from an Event that exists in a users' history. This handlebar is most commonly used in Audience Campaigns. Since CrossEngage stores a users' behaviour as events and attaches them to a user, you can access these events for content personalisation later.
{{#includeProducts '{
"eventProducts": {
"events": ["Viewed Product"],
"eventTimes": ["-2 weeks","now"],
"operator": "n-th last",
"operand": 1}
}'
}}
{{[properties.image]}}
{{/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.
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.