-
Notifications
You must be signed in to change notification settings - Fork 4
Update cookie consent response #1772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this work?
Summary
Add logic for accept and reject cookie.
Addresses
Changes
This PR Ensures:
console.log
statements meant for debuggingAdditional