Skip to content

Tracking User

To help improve and personalize the content of the Hello Retail products it is important that we have a way of tracking the behaviour of visitors on the webshop. All tracked actions are associated with a tracking user. The tracking user is identified by a trackingUserId. This trackingUserId is generated by Hello Retail.

When using the Hello Retail javascript the trackingUserId is generated automatically and stored in a first-party cookie. When using the Hello Retail SDK methods, or when using the managed Hello Retail solutions you don't have to do anything to handle the trackingUserId yourself. It is handled automatically.

If you want to use the REST API to create product recommendations, perform searches, or serve category pages you will need to pass the trackingUserId as a parameter to the API yourself. You have two ways of obtaining the trackingUserId. You can either use the SDK or our REST API.

Getting the trackingUserId using the SDK

You can use the SDK method getTrackingUserId in javascript. If you pass a callback to this method the callback will be called once the trackingUserId is available. The script will automatically store them in the cookie mentioned above and will make sure you get the same value on subsequent calls for the same visitor.

hrq = window.hrq || [];
hrq.push([
    "getTrackingUserId",
    function(trackingUserId) {
        // Here you can use the trackingUserId for your custom code       
    }
]);

Call the getTrackingUserId method, specifying a callback function - this callback function will be called with the user tracking ID passed along.

Arguments

Argument Type Description
callbackFunction String The callback function you would like to have called after this function is executed. The trackingUserId is passed as an argument to the callback function.

Example

This example will store the trackingUserId in a session cookie. You should be able to read this cookie on subsequent requests to your backend.

hrq = window.hrq || [];
hrq.push([
    "getTrackingUserId",
    function(trackingUserId) {
        document.cookie="helloRetailTrackingUserId=" + trackingUserId + ";path=/";
    }
]);
An alternative approach could be to use an XMLHttpRequest to send the trackingUserId to your backend and store it in some form of session storage. Remember that the value is associated with a specific visitor, and should not be shared across different visitors.

Getting the trackingUserId using the REST API

The Hello Retail SDK uses a REST API endpoint to create a trackingUserId if a valid one is not found in the first-party cookie. This endpoint can also be used directly. Notice that the endpoint will create a new trackingUserId on every request. The correct way of using this endpoint is to store the generated value in some form of session storage or a cookie so that it is associated with the visitor on the site. You should not generate a new trackingUserId on each request for the same user.

Request

The endpoint is available at https://core.helloretail.com/serve/trackingUser. You use it by sending an HTTP POST request with a JSON body with the websiteUuid of the requesting site. The content type must be application/json or text/plain 1.

Example of the structure the JSON body must have:

{
    "websiteUuid": "{website uuid}"
}

Response

The response will be a json object with a single id attribute. A successful response will have the 200 response code. The body of the response will look like this:

{
    "success": true,
    "id": "1234567890abcdefghijklmno"
}

If the API call fails for some unexpected reason return with a 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