diff --git a/EssentialCSharp.Web/wwwroot/js/clarity-manager.js b/EssentialCSharp.Web/wwwroot/js/clarity-manager.js index bfa62076..eafb8a5b 100644 --- a/EssentialCSharp.Web/wwwroot/js/clarity-manager.js +++ b/EssentialCSharp.Web/wwwroot/js/clarity-manager.js @@ -53,6 +53,24 @@ return clarityLoadPromise; } + function clearClarityCookies() { + const clarityCookies = ['_clck', '_clsk', 'CLID', 'ANONCHK', 'MR', 'MUID', 'SM']; + const expired = 'expires=Thu, 01 Jan 1970 00:00:00 GMT'; + const secure = window.location.protocol === 'https:' ? ';Secure' : ''; + const hostname = window.location.hostname; + const parts = hostname.split('.'); + const domains = [hostname]; + for (let i = 0; i < parts.length - 1; i++) { + domains.push('.' + parts.slice(i).join('.')); + } + clarityCookies.forEach(name => { + document.cookie = `${name}=;${expired};path=/${secure}`; + domains.forEach(domain => { + document.cookie = `${name}=;${expired};path=/;domain=${domain}${secure}`; + }); + }); + } + function updateConsent() { if (typeof window.clarity === "function") { try { @@ -68,6 +86,7 @@ function syncConsentState() { if (!hasAnalyticsConsent()) { updateConsent(); + clearClarityCookies(); return; } diff --git a/EssentialCSharp.Web/wwwroot/js/consent-manager.js b/EssentialCSharp.Web/wwwroot/js/consent-manager.js index 2775662e..67f78d13 100644 --- a/EssentialCSharp.Web/wwwroot/js/consent-manager.js +++ b/EssentialCSharp.Web/wwwroot/js/consent-manager.js @@ -170,6 +170,11 @@ class ConsentManager { showCustomizeOptions() { const details = document.getElementById('consent-details'); if (details) { + const isExpanded = details.style.display !== 'none' && details.style.display !== ''; + if (isExpanded) { + details.style.display = 'none'; + return; + } details.style.display = 'block'; // Load current preferences into checkboxes