Tracking Service

Prev Next

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

item

object

The item/product to track

item.id

string

The id of the item/product

item.name

string

The name of the item/product

item.price

string

The price of the item/product

item.currency

string

The currency of the item/product. Ex. USD

context

object

Dynamic information about the event.

categoryView

categoryView

Description: Tracks a category view event.

Parameters

Name

Type

Required

Description

category

string

The category to track

items

string[]

The ids of the first few category items/products

context

object

Dynamic information about the event.

addToCart

addToCart

Description: Tracks an add to cart event.

Parameters

Name

Type

Required

Description

item

object

The item/product to track

item.id

string

The id of the item/product

item.name

string

The name of the item/product

item.price

string

The price of the item/product

item.currency

string

The currency of the item/product. Ex. USD

item.quantity

number

The quantity of the item/product

context

object

Dynamic information about the event.

purchaseOrder

Description: Tracks an add to cart event.

Parameters

Name

Type

Required

Description

items

item[]

The array of items/products to track

item.id

string

The id of the item/product

item.name

string

The name of the item/product

item.price

string

The price of the item/product

item.currency

string

The currency of the item/product. Ex. USD

item.quantity

number

The quantity of the item/product

orderId

string

The unique identifier of the order

tax

number

The tax amount of the order

discount

number

The discount amount of the order

context

object

Dynamic information about the event.

elementView

elementView

Description: Tracks the view of a specific dom node.

Parameters

Name

Type

Required

Description

element

object

Information about the dom node to track

element.id

string

The id of the dom node

element.items

string[]

An array of the items/product ids shown in the element

context

object

Dynamic information about the event.

elementRender

elementRender

Description: Tracks the render of a specific dom node.

Parameters

Name

Type

Required

Description

element

object

Information about the dom node to track

element.id

string

The id of the dom node

element.items

string[]

An array of the items/product ids shown in the element

context

object

Dynamic information about the event.

elementClick

elementClick

Description: Tracks the render of a specific dom node.

Parameters

Name

Type

Required

Description

element

object

Information about the dom node to track

element.id

string

The id of the dom node

element.items

string[]

An array of the items/product ids shown in the element

item

string

The id of the item/product clicked

context

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

query

object

Information about the dom node to track

queryId

string

The id of the search query

deploymentId

string

The id of the deployment

isTypeToSearch

boolean

Whether the query is a type-to-search query

page

number

The page number of the search query

context

object

Dynamic information about the event.

searchResult

searchResult

Description: Tracks the results of the search request.

Parameters

Name

Type

Required

Description

query

object

Information about the dom node to track

queryId

string

The id of the search query

deploymentId

string

The id of the deployment

items

string[]

An array of the items/product ids in the search results

isTypeToSearch

boolean

Whether the query is a type-to-search query

page

number

The page number of the search query

context

object

Dynamic information about the event.

searchClick

searchClick

Description: Tracks a click event on a search result.

Parameters

Name

Type

Required

Description

query

object

Information about the dom node to track

queryId

string

The id of the search query

deploymentId

string

The id of the deployment

item

string

The id of the item/product clicked

items

string[]

An array of the items/product ids in the search results

isTypeToSearch

boolean

Whether the query is a type-to-search query

page

number

The page number of the search query

context

object

Dynamic information about the event.

customEvent

customEvent

Description: Tracks a custom event.

Parameters

Name

Type

Required

Description

category

string

The category of the event type

action

string

The action of the event

name

string

The name of the event

value

string

The value of the event

context

object

Dynamic information about the event.