Skip to content

consentsService.saved

consentsService.saved is an event on the Event Bus that occurs whenever consents are saved.

Event body

The consentsService.saved body has a Consent[] type which represents the list of currently granted consents. It is optional so it might not exist.

Example

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

useStorefront(async (storefront) => {
    storefront.eventBus.on('consentsService.saved', ({ body: consents }) => {
        console.log('Consents have been saved:', consents);
    });
});

Example

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

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

    const pastSavedEvents = messageStorageApi.getChannelMessages('consentsService.saved');

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

JS API reference