analytics.addedToWishlist¶
analytics.addedToWishlist is an event on the Event Bus that occurs after a user has added an item to the wishlist. This event only dispatches when analytics is enabled in the shop.
Event body¶
none
Example¶
In this example we listen to analytics.addedToWishlist event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
storefront.eventBus.on('analytics.addedToWishlist', () => {
console.log('A user has added an item to the wishlist')
});
});
Example (Recommended)¶
In this example we listen to analytics.addedToWishlist event using type-safe event constants. This approach is recommended as it provides better IDE support, helps prevent typos, and ensures that changes to event names are automatically reflected in your code.
useStorefront(async (storefront) => {
const analyticsEvents = storefront.events.analytics;
storefront.eventBus.on(analyticsEvents.addedToWishlist, () => {
console.log('A user has added an item to the wishlist')
});
});
Example¶
In this example we use a Message Storage API to retrieve an array of past analytics.addedToWishlist events.
useStorefront((storefront) => {
const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');
const pastAddedToWishlistEvents = messageStorageApi.getChannelMessages('analytics.addedToWishlist');
if (pastAddedToWishlistEvents.length > 0) {
pastAddedToWishlistEvents.forEach(({ body: eventBody }) => {
console.log('perform action on every past event');
});
}
});