contao-cookiebar icon indicating copy to clipboard operation
contao-cookiebar copied to clipboard

Load gtm.js explicit over googletagmanager.com/gtm.js for debugging purposes

Open akroii opened this issue 2 years ago • 15 comments

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.

akroii avatar Oct 04 '22 13:10 akroii

Is this supposed to be a hint or a bug? 😅

doishub avatar Oct 05 '22 06:10 doishub

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). 🤔

akroii avatar Oct 05 '22 06:10 akroii

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?

doishub avatar Oct 05 '22 07:10 doishub

that would be enough, to make the url selectable

akroii avatar Oct 05 '22 07:10 akroii

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.

doishub avatar Oct 05 '22 07:10 doishub

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>

akroii avatar Oct 05 '22 10:10 akroii

In my opinion it would be the easiest way to add another option here: image

akroii avatar Oct 07 '22 13:10 akroii

Yes I think that is the right way. Is it possible for you to provide a PR for it?

doishub avatar Oct 07 '22 13:10 doishub

For reference, this is what Contao is using now: https://github.com/contao/contao/pull/4887

fritzmg avatar Oct 08 '22 12:10 fritzmg

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 :(

akroii avatar Oct 11 '22 17:10 akroii

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?

doishub avatar Oct 18 '22 07:10 doishub

I have to test it.

akroii avatar Oct 18 '22 07:10 akroii

That would be nice. I am currently working on a major update in which I could consider it directly.

doishub avatar Oct 18 '22 08:10 doishub

@akroii Did you test it already?

zoglo avatar Oct 27 '22 20:10 zoglo

Not yet, i'm on it

akroii avatar Oct 28 '22 08:10 akroii

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.

akroii avatar Nov 01 '22 15:11 akroii

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?

Shoekrates avatar Sep 14 '23 09:09 Shoekrates

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.

Shoekrates avatar Sep 14 '23 10:09 Shoekrates

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 :)

akroii avatar Sep 14 '23 16:09 akroii

Seems like this has fixed itself after a lot of waiting time: https://developers.google.com/tag-platform

gtag.js is now Google Tag 🤷

zoglo avatar Feb 15 '24 13:02 zoglo