swte

custom GTM event

Oct 1st, 2025
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener('mhcookie/gcmv2', function(){
  2.     const consentTypes = mhCookie.consentTypes;
  3.  
  4.     // Reset consents
  5.     Object.keys(consentTypes).forEach(function(key){
  6.         if(key !== 'security_storage'){
  7.               consentTypes[key] = 'denied';
  8.         }
  9.     });
  10.  
  11.     if (mhCookie.userConsent.groups.includes('all') || mhCookie.userConsent.groups.includes('marketing')){
  12.         Object.keys(consentTypes).forEach(function(key){
  13.               consentTypes[key] = 'granted';
  14.         });
  15.     }
  16.  
  17.     if (mhCookie.userConsent.groups.includes('analytics')){
  18.         consentTypes.analytics_storage = 'granted';
  19.     }
  20.  
  21.     if (mhCookie.userConsent.groups.includes('functional') || mhCookie.userConsent.groups.includes('other')){
  22.         consentTypes.functionality_storage = 'granted';
  23.     }
  24.  
  25.     dataLayer.push({event: "cookie_consent_update", consentTypes);        
  26. });
Advertisement
Add Comment
Please, Sign In to add comment