Skip to content

JavaScript API

Command Overview

To track visitors' activity on your website using the JavaScript API, you have to push commands to a command queue inside a global object called kd (available on all the website pages where you added the tracking code). A command is represented by an array:

Example of a command

["command1", param1, param2]

The first element of the array corresponds to the command name (or command action), and the following optional elements correspond to parameters that specify the data needed by the command. When a command is added to the queue, it is not executed immediately (data is not immediately sent to the server). The execution is triggered by pushing the submit command. Once the submit command is added, the commands stored in the queue are sent to LYNX. Commands are added to the queue using the push method.

Example

kd.push(["view", "429500"]); //Add a "view" command. 
kd.push(["submit"]); //Add the "submit" command (with no parameters) to execute the "view" command.

Command Reference

cart

With the cart command you can track the status of your visitor's cart, sending to LYNX the items your visitors have added to their cart.

Description

This command tracks the items currently in the visitor’s shopping cart. It should be issued on the cart page and every time the customer adds/removes an item to/from the cart.

Usage

["cart", items]

Parameters

ParameterTypeDescription
itemsobjectAn array of items with the following properties:
  • item (string): The parent item's identifier (e.g. item group id).
  • quantity (number): The quantity of this item added the cart.
  • price (number): The item's price.
  • uniqueItemId (string): The item's unique identifier (e.g. SKU).

Example

js
kd.push(["cart", [
        {"item": "4459", "price": 15, "quantity": 1, "uniqueItemId":"4459010"},
        {"item": "5960", "price": 35, "quantity": 4, "uniqueItemId":"5960012"}
     ]
]);

// Add the "submit" command to send the data to LYNX.
kd.push(["submit"]);

category

The category command allows you to track the category a visitor is currently browsing.

Description

It tracks the category currently being browsed. Should be issued on category pages.

Usage

["category", category]

Parameters

ParameterTypeDescription
categorystringThe product category description (e.g. "skirts")

Example

js
kd.push(["category", "skirts"]);
// Add the "submit" command to send the data to LYNX.
kd.push(["submit"]);

purchase

The purchase command allows tracking purchases in your web store.

Description

Tracks a purchase event. This command should be issued on your web store checkout confirmation page.

Usage

["purchase", purchaseObject]

Parameters

ParameterTypeDescription
purchaseObjectobjectThe purchase description object:
  • orderId (string): The purchase unique identifier.
  • items (array of objects): The items purchased. Purchased item properties:
    • item (string): The parent item's identifier (e.g. item group id).
    • quantity (number): The quantity of the item purchased.
    • price (number): The item's price.
    • uniqueItemId (string): The item's unique identifier (e.g. SKU).

Example

js
kd.push(["purchase", {
    "orderId": "786222",
    "items": [
      {"item": "4459", "price": 99.9, "quantity": 1, "uniqueItemId":"4459010"},
      {"item": "5960", "price": 39.7, "quantity": 4, "uniqueItemId":"5960012"}
    ]
}]);
// Add the "submit" command to send the data to LYNX.
kd.push(["submit"]);

rate

The rate command is used to collect explicit user ratings on items.

Description

Reports the user's rating for an item. Issue this command on the item's rating confirmation page.

Usage

["rate", itemId, value]

Parameters

ParameterTypeDescription
itemIdstringThe unique identifier of the item
valuenumberRating value

Example

js
kd.push(["rate", "item-23", 4]);
// Add the "submit" command to send the data to LYNX.
kd.push(["submit"]);

setCustomerId

Description

Sets your customer identifier for known visitors. Issue this command when you are able to identify the current visitor (e.g. after login). This command is different from all the other commands in that it is executed immediately after being pushed to the command queue. It doesn't send any data to the server since it sets the customer identifier in the browser's cookie, and therefore, the submit command is not required for its execution.

Usage

["setCustomerId", customerId]

Parameters

ParameterTypeDescription
customerIdstringYour unique customer identifier

Example

js
kd.push(["setCustomerId", "1234ABC78"]);

submit

Description

Triggers the execution of the commands stored in the command queue. submit should be issued on the website pages where you want to execute the commands previously added to the queue.

Usage

["submit"]

Parameters

No parameters.

Example

js
kd.push(["view", "4459"]);
// Add the "submit" command to send the data to LYNX.
kd.push(["submit"]);

view

The view command allows tracking products that visitors view on your website.

Description

Tracks a product view. Issue this command on product pages.

Usage

["view", itemId]

Parameters

ParameterTypeDescription
itemIdstringThe parent item's identifier (e.g. item group id).

Example

js
kd.push(["view", "4459"]);
// Add the "submit" command to send the data to LYNX.
kd.push(["submit"]);