contao-cookiebar
contao-cookiebar copied to clipboard
Load gtm.js explicit over googletagmanager.com/gtm.js for debugging purposes
Hi,
we have some troubles if we want to debug our gtm property.
When we load gtm with:
https://www.googletagmanager.com/gtag/js?id=
we can not use debug features in google tag manager.
But if we use custom script with
https://www.googletagmanager.com/gtm.js?id=
everything works properly. This means we can use debugging features in google tag manager.
Is this supposed to be a hint or a bug? 😅
Hmm I don't know. Maybe you can seperate between Google Analytics and GTM in Cookiebar Config. See here: https://www.analyticsmania.com/post/gtag-vs-google-tag-manager/
GTM wants to fetch a special URL (https://www.googletagmanager.com/gtag/js), but can't recognize it and throws an error.
For google it is not the same, although the same javascript comes out of both urls (https://www.googletagmanager.com/gtag/js
and https://www.googletagmanager.com/gtm.js
). 🤔
Okay, do I see that correctly, that we should make the source URL selectable here in the Google Analytics
cookie type or would that not be enough?
that would be enough, to make the url selectable
Unfortunately, I can't quite figure it out. Embedding the following code requires it in both cases?
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());
At least, I strongly assume so.
Stick to documentation of GTM and Analytics:
GTM [gtm.js] (https://developers.google.com/tag-platform/tag-manager/web/datalayer)
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'[https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);](https://www.googletagmanager.com/gtm.js?id=%27+i+dl;f.parentNode.insertBefore(j,f);)
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
Analytics [gtag.js] (https://developers.google.com/analytics/devguides/collection/gtagjs)
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID');
</script>
In my opinion it would be the easiest way to add another option here:
Yes I think that is the right way. Is it possible for you to provide a PR for it?
For reference, this is what Contao is using now: https://github.com/contao/contao/pull/4887
Yes I think that is the right way. Is it possible for you to provide a PR for it?
Unfortunately at the current time i'm in a lack of time :(
For reference, this is what Contao is using now: https://github.com/contao/contao/pull/4887
It looks like both variants would work with the following code, which is why I would adjust the current cookie type accordingly:
// Source: https://www.googletagmanager.com/gtag/js?id=vendorID
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'vendorID', {'anonymize_ip': true});
Still, I would add the source URL in this cookie type so you can choose between gtag/js and gtag.js. Would that be enough for your purposes @akroii?
I have to test it.
That would be nice. I am currently working on a major update in which I could consider it directly.
@akroii Did you test it already?
Not yet, i'm on it
For reference, this is what Contao is using now: contao/contao#4887
It looks like both variants would work with the following code, which is why I would adjust the current cookie type accordingly:
// Source: https://www.googletagmanager.com/gtag/js?id=vendorID window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'vendorID', {'anonymize_ip': true});
Still, I would add the source URL in this cookie type so you can choose between gtag/js and gtag.js. Would that be enough for your purposes @akroii?
it would be sufficient if you could make the source (gtag.js or gtm.js) selectable.
It is not a problem with the script (window.dataLayer) itself but only to the
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
or
<script async src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXX"></script>
must be somewhere in html.
Several hints in this thread but I somehow miss a solution via cookiebar configuration. Or I just did not understand it :)
We just got the feedback that debug mode of gtm with our standard integration via cookie bar (cookie type “google analytics”) does not work whereas tracking does work.
The JS path currently used is https://www.googletagmanager.com/gtag/js?id=GTM-XXXXXX and it should be https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXX
What do I have to change to use the other path and to make debugging in GTM work?
Ah, I found this issue: https://github.com/oveleon/contao-cookiebar/issues/121 where it is said to use a custom script. First impression is good. I'll give it a try.
Several hints in this thread but I somehow miss a solution via cookiebar configuration. Or I just did not understand it :)
We just got the feedback that debug mode of gtm with our standard integration via cookie bar (cookie type “google analytics”) does not work whereas tracking does work.
The JS path currently used is https://www.googletagmanager.com/gtag/js?id=GTM-XXXXXX and it should be https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXX
What do I have to change to use the other path and to make debugging in GTM work?
This ticket is only when you use the 'Debug' Features in Analytics via Its Toolbar. See https://support.google.com/analytics/answer/7201382?hl=en#zippy=%2Cgoogle-tag-gtagjs
You have to use custom script :)
Seems like this has fixed itself after a lot of waiting time: https://developers.google.com/tag-platform
gtag.js is now Google Tag 🤷