trackCompetitionElement()

Prev

trackConpetitionElement() is used to track non-XGen elements by adding a query parameter to their product URLs. This will allow both XGen analytics and external services such as Google Analytics to easily view the data on element clicks.

Note: XGen elements automatically have a query parameter added to their links.

Syntax

trackCompetitionElement(selector, parameterKey, parameterValue);

Parameters

selector

type: string (query selector)
description: The query selector that matches an element you want to track. The query parameter you want to add will be applied to every link within every element that matches this selector.

parameterKey

type: string
description: The key of the query parameter that will be included in the links within the desired element. Ex: ?key=value

parameterValue

type: string
description: The value of the query parameter that will be included in the links within the desired element. Ex: ?key=value

Return Value

This function has no return value.

Examples

Basic query parameter tracking

In this example we are adding tracking to an element that matches the '.recommendedProducts' selector. We are then adding oldElement=element_12345 to the URL. The key and value can be set to whatever you want. In this case we are calling the parameter 'oldElement' and setting the value to a made up element ID. Now if a user clicks on a link contained within the targeted element, the link will include a query parameter that can be viewed within analytics.

// Import the integration from the 'installation' step
import { integration } from './xgenSdkIntegration';

// Track element
integration.trackCompetitionElement(
  '.recommendedProducts',
  'oldElement',
  'element_12345'
);