Home > widget-integration > RecommendationService > getRecentlyViewedProductIds

RecommendationService.getRecentlyViewedProductIds() method

Retrieves product IDs for recently viewed products.

This method can be overridden to customize which recently viewed products should be used for recommendations (e.g., filtering by category, availability, or recency threshold).

Signature:

protected getRecentlyViewedProductIds(): Promise<(string | number)[]>;

Returns:

Promise<(string | number)[]>

Promise resolving to array of product IDs (string or number) from the recently viewed products storage. Returns empty array if no recently viewed products exist.

Example

Override to filter recently viewed products by category:

protected async getRecentlyViewedProductIds(): Promise<(string | number)[]> {
  const productIds = await super.getRecentlyViewedProductIds();
  // Only return products from last 7 days in specific categories
  return this.filterRecentProducts(productIds, {
    maxDays: 7,
    categories: ['electronics', 'home-goods']
  });
}