--- title: "getRecentlyViewed()" slug: "getrecentlyviewed" updated: 2024-06-13T14:14:31Z published: 2024-06-13T14:14:31Z canonical: "docs.xgen.ai/getrecentlyviewed" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.xgen.ai/llms.txt > Use this file to discover all available pages before exploring further. # getRecentlyViewed() `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()](/v1/docs/setpdpproduct) function. #### Syntax ```javascript 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. ```javascript // 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]); ```