-
Notifications
You must be signed in to change notification settings - Fork 464
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
refactor: simplify GTM logic + unmount on permission removal #1047
Conversation
Deploying with Cloudflare Pages
|
ESLint Summary View Full Report
Report generated by eslint-plus-action |
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.
Left suggestions in the code to allow stacking pre-init events as you had in another PR.
We want to discuss event stacking with legal as the team is concerned regarding consent. |
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.
Looks good!
Let's merge after 1.0.4, tho.
Just for future reference: @johannesmoormann confirmed that we don't want to stack event prior to cookie agreement. |
ESLint Summary View Full Report
Report generated by eslint-plus-action |
Turns out GTM embeds several scripts of similar names: I've updated the code and it now removes them all. No error should be shown in the console anymore. |
Tried this again and I can still see the same issue. Can u check if the PR updated correctly? |
Despite unmounting the scripts, they remain in memory. @usame-algan and I will investigate this further. |
ESLint Summary View Full Report
Report generated by eslint-plus-action |
isInitialized: () => { | ||
const GTM_SCRIPT = 'https://www.googletagmanager.com/gtm.js' | ||
|
||
export const _getGtmDataLayerScript = (dataLayer: DataLayer) => { | ||
const script = document.createElement('script') | ||
return !!document.querySelector(`[src^="${GTM_SCRIPT}"]`) |
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.
Would it work if we checked that window.dataLayer
exists instead? It would be a bit simpler than querying the DOM.
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.
I would sooner check the DOM. We could manually push to window.dataLayer
and then this would return true
when GTM isn't initialised.
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.
Great idea to reload the page! 💯
I agree with the solution. I don't think people are enabling/disabling the analytics every 5 mins for the reload to be an inconvenience. |
ESLint Summary View Full Report
Report generated by eslint-plus-action |
Branch preview |
What it solves
Refactors GTM and adds
disale
functionality.How this PR fixes it
TagManager.initialize
andTagManager.dataLayer
have been simplified.TagManager,disable
isGtmLoaded
flag was also removed.How to test it
Refactor
pageview
works especially)Analytics changes
The GTM scripts are all removed on revocation.