Skip to content

title: Webcomponents - Event Bus - Events - Consents - {consentsName}.granted summary: {consentsName}.granted Event Bus event reference tags: - Webcomponents - Buses - Event Bus - Events - Consents events - {consentsName}.granted


{consentsName}.granted

{consentsName}.granted is an event on the Event Bus that occurs whenever consents are granted. It has four possible names as there are four possible consents. The full names of the event are:

  • analyticsConsent.granted
  • marketingConsent.granted
  • functionalConsent.granted
  • platformAnalyticsConsent.granted

Event body

none

Example

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

useStorefront(async (storefront) => {
    storefront.eventBus.on('analyticsConsent.granted', () => {
        console.log('Analytics consents have been granted');
    });
});

Example

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

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

    const pastGrantedEvents = messageStorageApi.getChannelMessages('analyticsConsent.granted');

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

JS API reference