-
Notifications
You must be signed in to change notification settings - Fork 140
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
Question: why are there new script tags created for every event? #3
Comments
Can you show me how do you implement it? |
So basically we do this before bootstrapping the app: const tagManagerArgs = {
gtmId: env.GOOGLE_TAG_MANAGER_TOKEN,
dataLayerName: 'PageDataLayer',
}
TagManager.initialize(tagManagerArgs) Then later on every route change we do this: const tagManagerArgs = {
dataLayer: {
event: 'VirtualPageview',
virtualPageURL: window.location.href,
virtualPageTitle: document.title,
},
dataLayerName: 'PageDataLayer',
}
TagManager.dataLayer(tagManagerArgs) We end up with a new script tag for each time the above is executed. I assume it's by design, but mainly wondering why :) |
@alinemorelli I don't get why his implementation would change this behaviour. Since it's the dataLayer method that creates a new script every time it's called https://github.com/alinemorelli/react-gtm/blob/master/src/TagManager.js#L46 I don't think that's really a good thing. |
Any update on this subject? |
https://github.com/alinemorelli/react-gtm/blob/master/src/TagManager.js#L47 the dataLayer appears to be initialized upon gtag first run (docs). It kinda serves as a page load, collects all the parameters and fires. it is not elegant but does the work |
Fixed on #22 |
It seems that for every event a new script tag is created in the head which reassigns the dataLayer and then pushes the event.
I wonder why this is, is it for SSR compatibility or some other reason?
The text was updated successfully, but these errors were encountered: