Skip to content

analytics.removedFromBasket

analytics.removedFromBasket is an event on the Event Bus that occurs after a user has removed an item from the basket. This event only dispatches when analytics is enabled in the shop.

Event body

none

Example

In this example we listen to analytics.removedFromBasket event and perform an action whenever it's emitted.

useStorefront(async (storefront) => {
    storefront.eventBus.on('analytics.removedFromBasket', () => {
        console.log('A user has removed an item from the basket')
    });
});

Example

In this example we use a Message Storage API to retrieve an array of past analytics.removedFromBasket events.

useStorefront((storefront) => {
    const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');

    const pastRemovedFromBasketEvents = messageStorageApi.getChannelMessages('analytics.removedFromBasket');

    if (pastRemovedFromBasketEvents.length > 0) {
        pastRemovedFromBasketEvents.forEach(({ body: eventBody }) => {
            console.log('perform action on every past event');
        });
    }
});

JS API reference