document.addEventListener('DOMContentLoaded', function () { var consentPopup = document.getElementById('consent-popup'); var acceptBtn = document.getElementById('accept-btn'); var denyBtn = document.getElementById('deny-btn'); var detailsBtn = document.getElementById('details-btn'); var detailsSection = document.getElementById('details-section'); // Display the consent pop-over if consent hasn't been given if (!consentGiven && consentPopup) { consentPopup.classList.remove('hidden'); } // Handle the Accept button click acceptBtn?.addEventListener('click', function () { saveConsent('accept'); consentPopup.classList.add('hidden'); }); // Handle the Deny button click denyBtn?.addEventListener('click', function () { saveConsent('deny'); consentPopup.classList.add('hidden'); }); // Handle the View Details button click detailsBtn?.addEventListener('click', function () { if (detailsSection.classList.contains('hidden')) { detailsSection.classList.remove('hidden'); detailsBtn.textContent = 'Hide Details'; } else { detailsSection.classList.add('hidden'); detailsBtn.textContent = 'View Details'; } }); // Function to send the user's choice to the server function saveConsent(choice) { fetch('inc-consent-handler.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin', body: JSON.stringify({ choice: choice }) }) .then(response => response.text()) .then(data => { data = JSON.parse(data); // Parse the response data as JSON if (data.choice == 'accept') { consentGiven = 'accept'; } else if (data.choice == 'deny') { consentGiven = 'deny'; } if (consentGiven == 'accept') { SettingsConsentGranted(); } else if (consentGiven == 'deny') { SettingsConsentDenied(); } }) .catch(error => { }); } function SettingsConsentGranted() { gtag('consent', 'update', { 'ad_storage': 'granted', 'ad_user_data': 'granted', 'ad_personalization': 'granted', 'analytics_storage': 'granted' }); } function SettingsConsentDenied() { gtag('consent', 'update', { 'ad_storage': 'denied', 'ad_user_data': 'denied', 'ad_personalization': 'denied', 'analytics_storage': 'granted' }); } });