Fetch from Tracking Event

includeProducts Function

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


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

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}

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.

Last updated