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