analytics.viewedItemList¶
analytics.viewedItemList
is an event on the Event Bus that occurs after a user has viewed a list of products. This event only dispatches when analytics is enabled in the shop.
Event body¶
none
Example¶
In this example we listen to analytics.viewedItemList
event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
storefront.eventBus.on('analytics.viewedItemList', () => {
console.log('A user has viewed a list of products')
});
});
Example¶
In this example we use a Message Storage API to retrieve an array of past analytics.viewedItemList
events.
useStorefront((storefront) => {
const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');
const pastViewedItemListEvents = messageStorageApi.getChannelMessages('analytics.viewedItemList');
if (pastViewedItemListEvents.length > 0) {
pastViewedItemListEvents.forEach(({ body: eventBody }) => {
console.log('perform action on every past event');
});
}
});