Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created April 28, 2026 08:36
Show Gist options
  • Select an option

  • Save webtoffee-git/03a096520d742a6de4f19f9e1ca3f52f to your computer and use it in GitHub Desktop.

Select an option

Save webtoffee-git/03a096520d742a6de4f19f9e1ca3f52f to your computer and use it in GitHub Desktop.
Execute or suppress a script immediately after the user makes a consent choice - By WebToffee
document.addEventListener("wcc_consent_update", function (eventData) {
const categories = eventData.detail.categories;
// Check if the analytics category was accepted
if (categories && categories.accepted && categories.accepted.includes('analytics')) {
console.log('Analytics consent: GRANTED');
// Initialize your analytics script here
} else {
console.log('Analytics consent: DENIED');
// Suppress or remove your analytics script here
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment