class GoogleTagManager { constructor() { this.dataLayer = window.dataLayer || []; this.cookieName = 'booomUserConsent'; this.personalizationCheckbox = document.getElementById('booom_personalization'); this.statisticsCheckbox = document.getElementById('booom_statistics'); this.marketingCheckbox = document.getElementById('booom_marketing'); } gtag() { this.dataLayer.push(arguments); } setCookie(value) { document.cookie = `${this.cookieName}=${value}; max-age=${365 * 24 * 60 * 60}; path=/`; } getCookie() { const cookies = document.cookie.split(';'); for (const cookie of cookies) { const [name, value] = cookie.trim().split('='); if (name === this.cookieName) { return value; } } return null; } fireConsentTrigger() { this.gtag('event', 'booom_consent_update'); } setDefaultConsent() { const previousConsent = this.getCookie(); if (previousConsent === 'rejected') { this.handleRejectAll('default'); } else if (previousConsent === 'accepted') { this.handleAcceptAll('default'); } else if (previousConsent) { const config = JSON.parse(previousConsent); this.personalizationCheckbox.checked = config.ad_personalization === 'granted'; this.statisticsCheckbox.checked = config.analytics_storage === 'granted'; this.marketingCheckbox.checked = config.ad_storage === 'granted'; this.handleAcceptSelected('default'); } else { // GEEN cookie aanwezig → alles op denied zetten als fallback this.gtag('consent', 'default', { ad_storage: 'denied', analytics_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', functionality_storage: 'denied', personalization_storage: 'denied', security_storage: 'denied', wait_for_update: 500 }); } } handleRejectAll(type) { this.personalizationCheckbox.checked = false; this.statisticsCheckbox.checked = false; this.marketingCheckbox.checked = false; this.gtag('consent', type, { ad_storage: 'denied', analytics_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', functionality_storage: 'denied', personalization_storage: 'denied', security_storage: 'denied', wait_for_update: 500 }); type === 'update' && this.setCookie('rejected'); this.consentPreference.hideBanner(); } handleAcceptAll(type) { this.personalizationCheckbox.checked = true; this.statisticsCheckbox.checked = true; this.marketingCheckbox.checked = true; this.gtag('consent', type, { ad_storage: 'granted', analytics_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'granted', functionality_storage: 'granted', personalization_storage: 'granted', security_storage: 'granted', wait_for_update: 500 }); type === 'update' && this.setCookie('accepted'); this.consentPreference.hideBanner(); } handleAcceptSelected(type) { const isPeronalizationChecked = this.personalizationCheckbox.checked ? 'granted' : 'denied'; const isStatisticsChecked = this.statisticsCheckbox.checked ? 'granted' : 'denied'; const isMarketingChecked = this.marketingCheckbox.checked ? 'granted' : 'denied'; const config = { ad_storage: isMarketingChecked, analytics_storage: isStatisticsChecked, ad_user_data: isStatisticsChecked, ad_personalization: isPeronalizationChecked, functionality_storage: isMarketingChecked, personalization_storage: isPeronalizationChecked, security_storage: isPeronalizationChecked, wait_for_update: 500 }; this.gtag('consent', type, config); type === 'update' && this.setCookie(JSON.stringify(config)); this.consentPreference.hideBanner(); } } class ConsentPreference { constructor() { this.placeholder = document.querySelector('.booom-cookie-consent__placeholder'); this.banner = document.getElementById('booom-cookie-consent'); this.rejectButton = document.getElementById('booom-reject-all'); this.acceptButton = document.getElementById('booom-accept-all'); this.acceptSelectionButton = document.getElementById('booom-save-preferences'); this.customizeButton = document.getElementById('booom-customize'); } init() { this.rejectButton.addEventListener('click', () => { this.gtm.handleRejectAll('update'); }); this.acceptButton.addEventListener('click', () => { this.gtm.handleAcceptAll('update'); }); this.gtm.getCookie() ? this.banner.classList.add('booom-cookie-consent--hidden') : this.banner.classList.remove('booom-cookie-consent--hidden'); this.customizeButton.addEventListener('click', () => { this.showDetailedConsent(); }); this.placeholder.addEventListener('click', () => { this.showBanner(); }); this.acceptSelectionButton.addEventListener('click', () => { this.gtm.handleAcceptSelected('update'); }); } hideBanner() { this.banner.classList.remove('booom-cookie-consent--detailed'); this.banner.classList.add('booom-cookie-consent--hidden'); } showBanner() { this.banner.classList.remove('booom-cookie-consent--hidden'); } showDetailedConsent() { this.banner.classList.add('booom-cookie-consent--detailed'); } } document.addEventListener('DOMContentLoaded', function () { const gtm = new GoogleTagManager(); const consentPreference = new ConsentPreference(); gtm.consentPreference = consentPreference; consentPreference.gtm = gtm; gtm.setDefaultConsent(); gtm.fireConsentTrigger(); consentPreference.init(); });