Home > widget-integration > FilterHandler > trackSelectedProductPage

FilterHandler.trackSelectedProductPage() method

Tracks the selected product page for analytics and session storage.

Calculates and stores the actual page number where a product was selected, accounting for different pagination types (default, load_more, infinite_scroll). This information is used for maintaining user context when returning from product detail pages. Override this method to customize page tracking logic or add additional analytics tracking.

Signature:

trackSelectedProductPage(index: number, productId: string): void;

Parameters

Parameter

Type

Description

index

number

The zero-based index of the product in the current product list

productId

string

The unique product ID string

Returns:

void

Remarks

Pagination type calculations: - default: Uses current page from URL - load_more: Accumulates pages from previous page + calculated page - infinite_scroll: Same as load_more

Stores in session storage: - SELECTED_PRODUCT_PAGE: The calculated page number - SELECTED_PRODUCT_ID: The product ID - COLLECTION_SELECTED: The current collection handle

Example

Extend to add custom analytics tracking:

window.boostWidgetIntegration.extend('FilterHandler', (FilterHandler) => {
  return class CustomFilterHandler extends FilterHandler {
    trackSelectedProductPage(index, productId) {
      super.trackSelectedProductPage(index, productId);

      // Send to custom analytics service
      analytics.track('product_selected', {
        product_id: productId,
        position: index + 1,
        collection: this.filterService.getCurrentCollection()
      });
    }
  };
});