trackCategoryView()

Prev Next

trackCategoryView() is used to track when a user views a category which is typically done on a Product Listing Page (PLP). This is primarily used to enhance XGen’s prediction performance.

Syntax

trackCategoryView(category);

Parameters

category

type: string
description: The category or PLP page that the user is currently viewing. This should match a value in either product_types or product_categories within the XGen catalog.

Return Value

This function has no return value.

Examples

Tracking a category view event

In this example we are grabbing the category from the URL and passing it into the trackCategoryView() function.

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

// Extracting the category from the URL using regex (grabs the last item in the path)
const category = /\/(?<category>[^/]+)\/?$/.exec(location.pathname)?.groups?.category;

// Send the category view event
integration.trackCategoryView(category);