Methods
// tracks a page view event
xg.track.pageView();
// tracks the view of a item/product
xg.track.itemView({item, context});
// tracks the view of a category
xg.track.categoryView({category, items, context});
// tracks an add to cart event for an item/product
xg.track.addToCart({item, context});
// tracks a purchase order event for item(s)/product(s)
xg.track.purchaseOrder({items, orderId, tax, discount, context });
// tracks the view of a specific dom element
xg.track.elementView({element, context});
// tracks the render of a specific dom element
xg.track.elementRender({element, context});
// tracks the click of a specific dom element
xg.track.elementClick({element, item, context });
// tracks a search query event (tracked by default when calling xg.search.getResults())
xg.track.searchQuery({query, queryId, deploymentId, page, context});
// tracks the results of a search query (tracked by default when calling xg.search.getResults())
xg.track.searchResult({query, queryId, deploymentId, page, context});
// tracks a click of a search item/product
xg.track.searchClick({query, queryId, deploymentId, page, item, items, context});
// tracks a custom event
xg.track.customEvent({category, action, name, value});
// batch tracking - this will batch tracking events until send() is called
const batch = xg.track.createBatch();
batch.pageView();
batch.itemView({item, context});
batch.send();
All Tracking Events Return
{
message: string;
success: boolean;
}
pageView
pageView
Description: Tracks a page view event.
Parameters
None
itemView
itemView
Description: Tracks a item/product view event.
Parameters
Name | Type | Required | Description |
| object | ✅ | The item/product to track |
↳
| string | ✅ | The id of the item/product |
↳
| string | ✅ | The name of the item/product |
↳
| string | ✅ | The price of the item/product |
↳
| string | ✅ | The currency of the item/product. Ex. USD |
| object | ❌ | Dynamic information about the event. |
categoryView
categoryView
Description: Tracks a category view event.
Parameters
Name | Type | Required | Description |
| string | ✅ | The category to track |
| string[] | ✅ | The ids of the first few category items/products |
| object | ❌ | Dynamic information about the event. |
addToCart
addToCart
Description: Tracks an add to cart event.
Parameters
Name | Type | Required | Description |
| object | ✅ | The item/product to track |
↳
| string | ✅ | The id of the item/product |
↳
| string | ✅ | The name of the item/product |
↳
| string | ✅ | The price of the item/product |
↳
| string | ✅ | The currency of the item/product. Ex. USD |
↳
| number | ✅ | The quantity of the item/product |
| object | ❌ | Dynamic information about the event. |
purchaseOrder
Description: Tracks an add to cart event.
Parameters
Name | Type | Required | Description |
| item[] | ✅ | The array of items/products to track |
↳
| string | ✅ | The id of the item/product |
↳
| string | ✅ | The name of the item/product |
↳
| string | ✅ | The price of the item/product |
↳
| string | ✅ | The currency of the item/product. Ex. USD |
↳
| number | ✅ | The quantity of the item/product |
| string | ✅ | The unique identifier of the order |
| number | ❌ | The tax amount of the order |
| number | ❌ | The discount amount of the order |
| object | ❌ | Dynamic information about the event. |
elementView
elementView
Description: Tracks the view of a specific dom node.
Parameters
Name | Type | Required | Description |
| object | ✅ | Information about the dom node to track |
↳
| string | ✅ | The id of the dom node |
↳
| string[] | ❌ | An array of the items/product ids shown in the element |
| object | ❌ | Dynamic information about the event. |
elementRender
elementRender
Description: Tracks the render of a specific dom node.
Parameters
Name | Type | Required | Description |
| object | ✅ | Information about the dom node to track |
↳
| string | ✅ | The id of the dom node |
↳
| string[] | ❌ | An array of the items/product ids shown in the element |
| object | ❌ | Dynamic information about the event. |
elementClick
elementClick
Description: Tracks the render of a specific dom node.
Parameters
Name | Type | Required | Description |
| object | ✅ | Information about the dom node to track |
↳
| string | ✅ | The id of the dom node |
↳
| string[] | ❌ | An array of the items/product ids shown in the element |
| string | ✅ | The id of the item/product clicked |
| object | ❌ | Dynamic information about the event. |
searchQuery
searchQuery
Description: Tracks the search query. This is an event right before the search request is sent.
Parameters
Name | Type | Required | Description |
| object | ✅ | Information about the dom node to track |
| string | ✅ | The id of the search query |
| string | ✅ | The id of the deployment |
| boolean | ❌ | Whether the query is a type-to-search query |
| number | ❌ | The page number of the search query |
| object | ❌ | Dynamic information about the event. |
searchResult
searchResult
Description: Tracks the results of the search request.
Parameters
Name | Type | Required | Description |
| object | ✅ | Information about the dom node to track |
| string | ✅ | The id of the search query |
| string | ✅ | The id of the deployment |
| string[] | ✅ | An array of the items/product ids in the search results |
| boolean | ❌ | Whether the query is a type-to-search query |
| number | ❌ | The page number of the search query |
| object | ❌ | Dynamic information about the event. |
searchClick
searchClick
Description: Tracks a click event on a search result.
Parameters
Name | Type | Required | Description |
| object | ✅ | Information about the dom node to track |
| string | ✅ | The id of the search query |
| string | ✅ | The id of the deployment |
| string | ✅ | The id of the item/product clicked |
| string[] | ❌ | An array of the items/product ids in the search results |
| boolean | ❌ | Whether the query is a type-to-search query |
| number | ❌ | The page number of the search query |
| object | ❌ | Dynamic information about the event. |
customEvent
customEvent
Description: Tracks a custom event.
Parameters
Name | Type | Required | Description |
| string | ✅ | The category of the event type |
| string | ✅ | The action of the event |
| string | ✅ | The name of the event |
| string | ✅ | The value of the event |
| object | ❌ | Dynamic information about the event. |