-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marco Blumendorf
committed
Jan 21, 2025
1 parent
1b80748
commit 06e13c4
Showing
10 changed files
with
72 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,23 @@ | ||
// Initialize dataLayer array if it doesn't exist | ||
if (!window.dataLayer) { | ||
window.dataLayer = []; | ||
} | ||
|
||
// Google Analytics Measurement ID | ||
const GA_MEASUREMENT_ID = 'G-MG5LDT8GT6'; | ||
|
||
// Create dummy gtag function if not loaded | ||
if (!window.gtag) { | ||
window.gtag = function (...args: Parameters<Window['gtag']>) { | ||
window.dataLayer.push(args); | ||
}; | ||
} | ||
|
||
// Initialize analytics with consent mode | ||
export function initializeGoogleAnalytics(): void { | ||
const script = document.createElement('script'); | ||
script.async = true; | ||
script.src = `https://www.googletagmanager.com/gtag/js?id=${GA_MEASUREMENT_ID}`; | ||
document.head.appendChild(script); | ||
import ReactGA from 'react-ga4'; | ||
|
||
script.onload = function () { | ||
window.dataLayer = window.dataLayer || []; | ||
window.gtag('js', new Date().toISOString()); | ||
window.gtag('config', GA_MEASUREMENT_ID, { | ||
'anonymize_ip': true // IP anonymization for GDPR | ||
}); | ||
}; | ||
declare global { | ||
interface Window { | ||
dataLayer: unknown[][]; | ||
gtag: (...args: unknown[]) => void; | ||
} | ||
} | ||
|
||
// Set default consent mode settings | ||
export function initializeConsentMode(): void { | ||
window.gtag('consent', 'default', { | ||
'analytics_storage': 'denied', | ||
'ad_storage': 'denied', | ||
'functionality_storage': 'denied', | ||
'personalization_storage': 'denied', | ||
'security_storage': 'granted' // Required for basic functionality | ||
export const initializeGoogleAnalytics = (measurementId: string): void => { | ||
ReactGA.initialize(measurementId, { | ||
// testMode: process.env.NODE_ENV === 'development', | ||
}); | ||
} | ||
}; | ||
|
||
// Update consent settings | ||
export function updateConsentState(consent: boolean): void { | ||
// Update consent state | ||
window.gtag('consent', 'update', { | ||
'analytics_storage': consent ? 'granted' : 'denied', | ||
'functionality_storage': 'granted', // Essential cookies always allowed | ||
'personalization_storage': consent ? 'granted' : 'denied' | ||
export const setAnalyticsConsent = (consent: boolean): void => { | ||
ReactGA.gtag('consent', 'update', { | ||
analytics_storage: consent ? 'granted' : 'denied', | ||
ad_storage: consent ? 'granted' : 'denied', | ||
ad_personalization: consent ? 'granted' : 'denied', | ||
ad_consent: consent ? 'granted' : 'denied', | ||
}); | ||
|
||
// Initialize analytics if consent is granted | ||
if (consent && !document.querySelector('script[src*="googletagmanager"]')) { | ||
initializeGoogleAnalytics(); | ||
} | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.