getRecentlyViewed()

Prev Next

getRecentlyViewed() is used to retrieve the recently viewed products the user has viewed. It will return the product IDs in the order they were viewed with the item at index 0 being the item that was most recently viewed. Only 12 products are saved to recently viewed at a time and if a product is viewed more than once, it will be removed from the list and added to the beginning.

Recently viewed can be set using the setPdpProduct() function.

Syntax

getRecentlyViewed();

Parameters

None.

Return Value

An array of product codes in order of when they were recently viewed. The item at index 0 was the most recently viewed product.

Examples

Get recently viewed items:

In this example, we get the list of recently viewed items and console log the most recently viewed item.

// Create integration (use existing integration if you already created one)
const integration = new XG(...config);

// Get list of recently viewed items
const recentlyViewed = integration.getRecentlyViewed();

// Console log most recently viewed
console.log('The last product ID you viewed was: ', recentlyViewed[0]);