Skip to content

Commit e769ef7

Browse files
fix: use window.gtag/window.clarity/window.dataLayer consistently
Replace bare gtag(), clarity(), and dataLayer identifiers with explicit window.* references so consent updates work correctly regardless of execution context (strict mode, bundlers, different script scopes).
1 parent 1f72a0b commit e769ef7

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class ConsentManager {
4242
// Ensure gtag infrastructure exists — the actual 'consent default' is set inline
4343
// in _Layout.cshtml before gtag.js loads (required by Google Consent Mode v2).
4444
window.dataLayer = window.dataLayer || [];
45-
function gtag(){dataLayer.push(arguments);}
46-
window.gtag = window.gtag || gtag;
45+
window.gtag = window.gtag || function(){window.dataLayer.push(arguments);};
4746
}
4847

4948
loadConsentPreferences() {
@@ -255,7 +254,7 @@ class ConsentManager {
255254
updateConsentMode() {
256255
if (window.gtag) {
257256
try {
258-
gtag('consent', 'update', this.consentState);
257+
window.gtag('consent', 'update', this.consentState);
259258
} catch (error) {
260259
console.warn('Failed to update Google Consent Mode:', error);
261260
}
@@ -266,7 +265,7 @@ class ConsentManager {
266265
// Send consent signal to Microsoft Clarity using Consent API v2
267266
if (window.clarity) {
268267
try {
269-
clarity('consentv2', {
268+
window.clarity('consentv2', {
270269
ad_storage: this.consentState.ad_storage,
271270
analytics_storage: this.consentState.analytics_storage
272271
});

0 commit comments

Comments
 (0)