Skip to content

Cart tracking

Hello Retail can use the current content of the visitors shopping cart as input to the personalization engine and as part of the data needed to be able to provide the Abandoned Cart functionality in the Triggered Emails product. It is therefore important to configure cart tracking when integrating with Hello Retail.

Cart tracking works by sending information about the contents of the cart to Hello Retail every time it changes. This is typically implemented using the javascript SDK but can also be implemented using the REST API. The tracked cart is associated with the visitors trackingUserId.

We have information about how to configure cart tracking for various platforms in on our support pages.

Cart tracking using the SDK

The current state of the cart can be set using the setCart method. The method accepts two arguments:

Arguments

Argument Type Description
data Cart object See specification of the cart object below.
callback() function Will be called without any arguments when cart tracking is finished. Optional.

Properties of the Cart object

Property Type Description
urls String[] A list of canonical urls of the products in the cart. They are used to identify the products in the cart, they must match the urls of the products given to Hello Retail in the product feed or when using the product REST API. You must provide either urls or productNumbers. If the cart is empty you can provide an empty list
productNumbers String[] A list of unique product numbers of the products in the cart. They are used to identify the products in the cart, they must match the product numbers of the products given to Hello Retail in the product feed or when using the product REST API. You must provide either urls or productNumbers. If the cart is empty you can provide an empty list
total String The total cart value. Optional.
url String A url that can be used to restore a shopping session with the current contents of the cart. This is used in abandoned cart emails to provide a link that will bring the visitor back to the shop in a state where they have the same products in their cart. Optional.
email String The email address of the customer. Optional.

Example of tracking using product urls

hrq = window.hrq || [];
hrq.push([
    "setCart", 
    {
        total: 123.50,
        url: 'https://shop.example.com/cart/123456789',
        urls: [
            'https://shop.example.com/t-shirt.html',
            'https://shop.example.com/shoes.html'
        ],
        email: 'customer@example.com'
    }, 
    function() {
        console.log('Cart has been tracked');
    }
]);

Example of tracking using product numbers

hrq = window.hrq || [];
hrq.push([
    "setCart",
    {
        total: 123.50,
        url: 'https://shop.example.com/cart/123456789',
        productNumbers: [
            'p-1234',
            'p-2134'
        ],
        email: 'customer@example.com'
    }, 
    function() {
        console.log('Cart has been tracked');
    }
]);

Example of clearing the cart contents

hrq = window.hrq || [];
hrq.push([
    "setCart",
    {
        total: 0,
        productNumbers: [],
        email: 'customer@example.com'
    }, 
    function() {
        console.log('Cart has been cleared');
    }
]);

Cart tracking using the REST API

The Hello Retail SDK uses a REST API endpoint to track the cart. This API can also be used directly.

Request

The endpoint is available at https://core.helloretail.com/serve/collect/cart. You use it by sending a HTTP POST request with a JSON body. The content type must be application/json or text/plain 1.

The JSON body must match the Cart Object documented for the javascript SDK above, but it must also contain the trackingUserId of the visitor and whe websiteUuid of the webshop.

Example of the structure the JSON body must have:

{
    "trackingUserId": "{tracking user id}",
    "websiteUuid": "{website uuid}",
    "total": 123.50,
    "url": "https://shop.example.com/cart/123456789",
    "productNumbers": [
        "p-1234",
        "p-2134"
    ],
    "email": "customer@example.com"
}

More information about each part of the JSON body

Property Type Description
trackingUserId String Tracking user id that has been generated by Hello Retail. You can read more about the tracking user here
websiteUuid String The id identifying the website in Hello Retail. This can be found on my.helloretail.com
urls String[] A list of canonical urls of the products in the cart. They are used to identify the products in the cart, they must match the urls of the products given to Hello Retail in the product feed or when using the product REST API. You must provide either urls or productNumbers. If the cart is empty you can provide an empty list
productNumbers String[] A list of unique product numbers of the products in the cart. They are used to identify the products in the cart, they must match the product numbers of the products given to Hello Retail in the product feed or when using the product REST API. You must provide either urls or productNumbers. If the cart is empty you can provide an empty list
total String The total cart value. Optional.
url String A url that can be used to restore a shopping session with the current contents of the cart. This is used in abandoned cart emails to provide a link that will bring the visitor back to the shop in a state where they have the same products in their cart. Optional.
email String The email address of the customer. Optional.

Response

The response will indicate if the tracking succeeded. A success response will have the 200 response code. The body of the response will look like this:

{
    "success": true,
    "message": "Cart tracked"
}

If the tracking fails because of invalid input the response will have the 400 response code. An example could be not supplying the websiteUuid or supplying a websiteUuid that does not match a website. This will result in the following response:

{
    "success": false,
    "message": "Website not found"
}

If the tracking fails for other reasons it will fail with the 500 response code. If you experience this please contact Hello Retail support.


  1. The reason for supporting text/plain is to allow requests to this endpoint, made from the browser, to be categorized as simple thereby avoiding CORS preflight requests. You can read more here https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests