function updateConsent(isAccepted) { const status = isAccepted ? 'granted' : 'denied'; // 1. Report to Google via Consent Mode gtag('consent', 'update', { 'ad_storage': status, 'ad_user_data': status, 'ad_personalization': status, 'analytics_storage': status }); // 2. Save the preference in a local cookie for 1 year const expiry = new Date(); expiry.setFullYear(expiry.getFullYear() + 1); document.cookie = `user_consent=${status}; expires=${expiry.toUTCString()}; path=/`; // 3. Hide the banner document.getElementById('cookie-banner').style.display = 'none'; } // Check if user has already consented on page load window.onload = function() { if (document.cookie.includes('user_consent=')) { document.getElementById('cookie-banner').style.display = 'none'; // If they already accepted, update Google immediately if (document.cookie.includes('user_consent=granted')) { gtag('consent', 'update', { 'ad_storage': 'granted', 'analytics_storage': 'granted' }); } } };