Skip to main content

Collection Viewed (collection_viewed)

Purpose: Track when a user lands on a collection listing page to browse a specific grouping of products. When to Fire: After your page or API loads the collection data and the associated product SKUs typically on page load or when your view changes to a collection view. Payload Schema:
FieldTypeDescription
collection_idstring or numberUnique identifier of the collection.
collection_namestringHuman‑readable collection name.
skuarray of stringsFlat array of SKUs for all products in this collection.
facetsarrayActive filters (e.g. size, brand)—each { field, value }. Use an empty array if none.
request_idstringUnique identifier for the search request (x-request-id from response headers).
page_depthstringCurrent page number (1, 2, 3, etc.).
Example:
// Assume these variables are populated from your collection response and UI state:
const collectionId      = 'cat123';
const collectionName    = 'Running Shoes';
const selectedFacets    = [];       // e.g. [{ field: 'size', value: '10' }]
const requestId         = collectionResponse.headers.get('x-request-id');
const currentPage       = 1;        // Current page number (1, 2, 3, etc.)
const products          = [
  { sku: 'RS-001', name: 'Lightweight Runner' },
  { sku: 'RS-002', name: 'Marathon Pro' }
];

ExpAnalyticsService.trackCollectionViewed({
  collection_id: collectionId,
  collection_name: collectionName,
  sku: products.map(p => p.sku),
  facets: selectedFacets,
  request_id: requestId,
  page_depth: currentPage
});