Conversation
|
| const loadGoogleAnalytics = useCallback(() => { | ||
| const consent = JSON.parse(sessionStorage.getItem('cookie-consent') || '{}'); | ||
|
|
||
| if (isAuthenticated || consent.analytics) { | ||
| const win = window as CustomWindow; | ||
|
|
||
| if (!win.gtag) { | ||
| const script = document.createElement('script'); | ||
| script.src = 'https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-X'; | ||
| script.async = true; | ||
| document.head.appendChild(script); | ||
|
|
||
| win.dataLayer = win.dataLayer || []; | ||
| win.gtag = (...args) => win.dataLayer!.push(args); | ||
| } | ||
|
|
||
| win.gtag('js', new Date()); | ||
| // TODO Add Google Analytics ID | ||
| win.gtag('config', 'UA-XXXXXXX-X', { anonymize_ip: true }); | ||
| } | ||
| }, [isAuthenticated]); |
There was a problem hiding this comment.
we don't need this, also this function is flawed.
Some of it are,
- The TAG should be the actual google analytics tag. i, e. the placeholder tag doesn't work.
- We should use GA4 tags.
- This loading is already handled by the plugin that installs google analytics
| }, [isAuthenticated]); | ||
|
|
||
| const handleAccept = useCallback(() => { | ||
| const consent = { analytics: true }; |
There was a problem hiding this comment.
We could just use a boolean here
| const gaScript = document.querySelector('script[src*="googletagmanager.com/gtag/js"]'); | ||
| if (gaScript) { | ||
| gaScript.remove(); | ||
| } |
There was a problem hiding this comment.
we don't need to remove the script all-together. we should just update the consent.
| } | ||
|
|
||
| // TODO: Add Google Analytics ID | ||
| window['ga-disable-UA-XXXXXXX-X'] = true; |
Summary
Add logic for accept and reject cookie.
Addresses
Changes
This PR Ensures:
console.logstatements meant for debuggingAdditional