From 7895dc78e19bbc76db15bdad620577ef88b75f42 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 7 Aug 2026 00:15:56 -0700 Subject: [PATCH] fix(consent): toggle customize panel and clear clarity cookies on revoke - showCustomizeOptions() now toggles #consent-details visibility: clicking Customize a second time collapses the panel instead of always showing it - clarity-manager.js: add clearClarityCookies() that erases _clck, _clsk, CLID, ANONCHK, MR, MUID, SM across all candidate domains; call it from syncConsentState() whenever analytics consent is denied (previously only the Withdraw path cleared these cookies) --- .../wwwroot/js/clarity-manager.js | 19 +++++++++++++++++++ .../wwwroot/js/consent-manager.js | 5 +++++ 2 files changed, 24 insertions(+) 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