changeConsent¶
changeConsent
is a DOM event that occurs whenever the consents are changed.
Event body¶
The changeConsent
body has a TConsentChangeEvent type which represents the details of the changed consent. It is optional so it might not exist.
Example¶
In this example we listen to changeConsent
event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
document.addEventListener('changeConsent', (event) => {
const detail = event.detail;
if (!detail) return;
const { name, checked } = detail;
if (checked) {
console.log(name, ' has been granted');
}
if (!checked) {
console.log(name, ' has been revoked');
}
});
});