Using Google Tag(gtag) with Google Tag Manager - google-tag-manager

I currently have an implementation of GA4 using gtag in my website and I would like to add GTM too. I was wondering if I can use the same endpoint from GA4 (https://www.googletagmanager.com/gtag/js?id=) and insert the GTM tag where id is and GA4 and GTM again with config.
I found this for the documentation
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script> but nothing that specifically talks about using Google Tag with Google Tag Manager. Almost all of it is about using the GTM interface.
I found that GTM supports googletag but the endpoint uses https://www.googletagmanager.com/gtm.js?

It's not recommended since GTM can load gtag and a bunch of other libraries as they're needed and manage them in the most optimal way. That's why you see a lot more information on GTM than gtag.
Implementing tracking with gtag.js is, in most cases, a mistake unless you don't care much about it and just want to be quick about it.
Having said that, yes, you can load both separately. GTM will attempt to use the existing gtag library if it needs it. Set up like this, however, requires you to understand how both libraries deploy listeners to the dataLayer array and how they store/use the local state of things. They will also use the same cookies.
Even though the libraries don't conflict in terms of syntax, it's uncommon to have logical tracking issues due to implementations like this.

Related

Google Tag Manager not collecting data when deployed to Vercel (Next js)

I am trying to use Google Tag Manager to collect event data (including page view) but it isn't feeding through to Google Analytics once its deployed to Vercel.
I have checked the following things:
GTM has a GA4 Configuration Tag with the measurement ID from GA
I have set up the GTM measurement ID as a public variable in env.local (and reflected this in Vercel)
T have added the script to _app.js
I have added the iframe to _document.js
Set up the tags required in GTM and published it
Using dev tools I have checked that the gtm script (with the correct reference) is fired in the Network tab
Also checked dataLayer in the Console tab is collecting the data expected
However, in spite of all of this I can't see any data in Google Analytics. Played around a bit yesterday expecting to see some today but nothing.
It seems to work on localhost and checking both in real time Vercel doesn't register a view but localhost does.
Previewing the Vercel URL from GTM does say its connected and I can view that in real time in GA when going this way, but if I go to the address directly it's not logging it. Checking 'Tag Coverage' on GTM also says the pages aren't connected.
Am I missing something? It seems to work in theory, just not in practice when visiting the Vercel address directly (as opposed to via GTM preview)?
Thank you in advance
I think I found an answer myself and it's rather basic. It seems a pop up blocker I had installed ('Pop up blocker for Chrome™ - Poper Blocker') was preventing it from firing. Disabling the extension seems to have done the job.

Is it possible to disable Google Tag Manager in a SPA after a user logs in?

I have a React app and want to install Google Tag Manager on certain pages, but I do not want it present after a user logs in. Is it possible to disable / remove the GTM scripts after a certain user action?
I am using react-gtm-module to install Google Tag Manager but open to other options.
Well, this, basically, answers it: How to unload a javascript from an html?
But a better answer would probably be: don't unload GTM. It's not a good practice. It adds a lot more complexity to your overall logic. People don't expect someone to arbitrarily override deployed scripts' namespaces. It's very likely to cause havoc at some point and it's unlikely the one to debug it would be thankful to you for a thoughtful implementation.
Instead, consider using blocking triggers within GTM to just prevent certain tags from firing.

Google Tag Manager and page load performance: does it reduces performance in PageSpeed Insights?

I know this may seem a bit vague, but I'm about to give more context: in the company I work for we use (my personal thought is we're misusing) Google Tag Manager (GTM) to inject some third party scripts inside GTM tags. Mostly we use it to manipulate the DOM in certain page templates (like, for instance, product pages) and inject third party scripts (examples are Zopim chat, Facebook pixel, etc…).
Things we tipically do are: manipulating the DOM when DOMContentLoaded and/or load events happen on page load, so It seems obvious to me that without these GTM tags our site will get a better score in PageSpeed Insights and in Chrome DevTools' Lighthouse. I can't test the website without GTM tags activated since it's already everywhere in the site.
How much is this kind of use of GTM harming our site speed?
There are a few different ways in which you can find out the performance impact of GTM and the third party tags.
Via the Developer tools
You can block gtm.js in your browser developer tools. This will prevent loading of Google tag manager and the associated tags. You can find out more about that feature here. Once you have done this, you can run Google Lighthouse from your browser, to see how your scores improve.
Via Webpagetest
You can also use Webpagetest to find out the performance without third party tags. Webpagetest has a request blocking feature or you can use the following Webpagetest script to test out the performance with only your first party domains.
blockDomainsExcept yourwebsite.com
navigate https://yourwebsite.com
This is to measure the performance impact of your third party scripts. You probably will get similar results if you include the third party scripts directly into your website without using GTM. That being said, there are ways to optimise your GTM setup for performance and to fully leverage the features of a tag manager to improve the performance of your website. You can check out this article if you are interested in optimizing your GTM setup.
Injecting tags is what GTM is for, so this does not constitute abuse.
GTM itself is just a delivery mechanism; it's one JS file (I think an empty container is some 100KB unzipped, and 30KB to download if your browser supports compression) with a mechanism for asynchronous loading of tags. By itself it will contribute very little to the page load time.
Of course the stuff you deploy via GTM might slow down your site a lot - partly because it will download external libraries, and partly because DOM manipulations might force reflows/repaints in the browser. However this is not due to GTM, this is due to the tags you use, and would happen exactly the same if you integrated Zopim etc. via some other means.
So, will using a lot of (potentially bad [1]) JavaScript make your site slow? In all likelihood, yes. It this the fault of GTM? It is not, other than in the sense that GTM makes integrating the nasty stuff a little easier.
[1] Not a dig against you, it's just that marketing tags are quite often written in appallingly outdated JavaScript.
Yes, it reduces the Lighthouse performance scores, especially the mobile ones. We have to be very careful adding GTM to our website, especially for the homepage. For my website, GTM was injecting another 5 JS files from different domains. This adds more Round-trip time (RTT)to our application and in-turn add more load to browser.
When I removed GTM from my homepage, it improved Lighthouse performance scores by 5 points. So there should be some kind of suggestions/insights provided by GTM itself whether it is going to impact our website or not.

Can I render google tag manager scripts server side?

I'm looking into google tag manager and would like to avoid making a request from the client to render the tags. Is it possible to request the tags from GTM on the server and render them up front?
No (*). Not only is GTM itself a client-side technology, most marketing tags likewise require to be run in the browser.
There are a few things like Google Analytics or Google Ads conversion tags that can be run on the server (although the implementation is very much different from the JS tags), but GTM has no part in that. If you want vaguely similar functionality to GTM that moves at least a part of your tags out of the client-side code you should look at a service like segment.com (I am not affiliated. Segment.com is not free).
Update Feb 2020: Google has announced a closed beta for server-side tracking, where you run a container in a cloud environment that then distributes the requests. Simo Ahava has a little info in his twitter feed: https://twitter.com/SimoAhava/status/1222459714614841346. This is not yet a production feature.
(*) Not in any meaningful sense of the world. Just to cover every angle, you could download the GTM javascript file and run it in a headless browser on the server or something similarly stupid, but there would be no point, and I just mentioning it to pre-empt smartass comment to that effect.

Google Analytics Universal and Classic

I have several different Google Analytics codes for several different purposes. With the one I recently created, GA automatically created it as Universal, without the option of Classic. However, I have several other trackers as Classic.
Is there a way to use both Google Analytics Universal and Classic codes on the same page?
I have too much to do a migration and change everything around, and need an option to use both codes on the same page.
Thanks for your help!...every time you help me you save a kitten!!
The "classic" code will track to classic properties or, for the time being, to properties that have been recently transferred to Universal Analytics. UA code will track only to UA enabled properties.
You can mix classic and universal code on properties that have been recently transfered to UA (altough at the moment I cannot find the reference for that in the docs, plus I'm not sure how this will work with cross domain tracking).
You can use both ga.ja and analytics.js without problems if they track to different properties (again, this will give you problems with cross domain tracking since they use different parameters to transfer the session between domains).

Resources