Skip to content

Commit 1f72a0b

Browse files
fix: remove unused options param; clear GA4 _ga_ prefix cookies on revoke
- Remove unused constructor(options) parameter and config-script wiring - clearTrackingCookies() now enumerates document.cookie to also delete _ga_<measurement-id> cookies set by GA4 (e.g. _ga_G-761B4BMK2R), which vary per property and cannot be hardcoded
1 parent 58d7b11 commit 1f72a0b

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

EssentialCSharp.Web/wwwroot/js/consent-manager.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
class ConsentManager {
8-
constructor(options = {}) {
8+
constructor() {
99
this.COOKIE_NAME = 'essential-csharp-consent';
1010
this.COOKIE_DURATION = 365; // days
1111
this.CONSENT_VERSION = '2'; // Bump this to re-prompt all users when consent terms change
@@ -449,7 +449,15 @@ class ConsentManager {
449449
for (let i = 0; i < parts.length - 1; i++) {
450450
domains.push('.' + parts.slice(i).join('.'));
451451
}
452-
trackingCookies.forEach(cookieName => {
452+
453+
// Also collect GA4 measurement-ID cookies (_ga_XXXXXXXX) from document.cookie
454+
// since their suffix changes per-property and can't be hardcoded.
455+
const ga4Cookies = document.cookie.split(';')
456+
.map(c => c.trim().split('=')[0])
457+
.filter(name => name.startsWith('_ga_'));
458+
const allCookies = [...new Set([...trackingCookies, ...ga4Cookies])];
459+
460+
allCookies.forEach(cookieName => {
453461
document.cookie = `${cookieName}=;${expired};path=/`;
454462
domains.forEach(domain => {
455463
document.cookie = `${cookieName}=;${expired};path=/;domain=${domain}`;
@@ -460,11 +468,7 @@ class ConsentManager {
460468

461469
// Initialize consent manager when DOM is ready
462470
document.addEventListener('DOMContentLoaded', function() {
463-
// Check for configuration from script tag data attributes
464-
const configScript = document.querySelector('script[data-consent-config]');
465-
const config = configScript ? JSON.parse(configScript.dataset.consentConfig) : {};
466-
467-
window.consentManager = new ConsentManager(config);
471+
window.consentManager = new ConsentManager();
468472
});
469473

470474
// Global function for opening consent preferences

0 commit comments

Comments
 (0)