Skip to content

JavaScript Library

The JavaScript library is built on top of the RESTful API and it is designed to make it easy to communicate with eSales from a site, both when fetching results and when notifying events.

API key and credentials

To be able to access and use the eSales API the customer on-boarding Pre-requirements must be fulfilled.


The first step to use the JavaScript library is to include the script in each HTML page communicating with eSales in some way.

Check JavaScript library version

Always check the latest JavaScript library version and make sure to use version 2.

Backwards compatibility

The JavaScript library for Web API v2 is not backwards compatible with Web API v1.

    <script type="text/javascript"

The JavaScript library exposes an esalesAPI object which is the base to all interactions with the eSales cluster in the HTML page. Once the script is included in the HTML page, the next step (and also a general recommendation) is to instantiate an api object by using the case sensitive Web API identifier for a cluster provided by Apptus and the market eSales should use to fetch content and group notifications.

var api = window.esalesAPI({ market: '{market}', clusterId: '{cluster-id}' });

Once the api object is instantiated a session key and a customer key are automatically generated (if not already present) and stored in cookies. The cookies, if present must be valid UUID v4 strings.

Default arguments

Some arguments will automatically be submitted via the JavaScript library when making panel queries and notifications, these are, esales.customerKey, and esales.sessionKey.


A session starts with the first interaction of a visitor that results in a query or notification via the RESTful API. The visitor is automatically assigned a randomized session and customer key which are both UUID v4 / GUID. A new customer key, a UUID supplied by the retailer website, will be assigned to the visitor when the visitor signs in to the website.

A session ends when the visitor signs out and the end session notification is sent. The set cookies are cleared and a new randomized session customer key is generated.

The default level of personalisation for the JavaScript library is the Medium level of personalisation.

Detailed information