Is it possible to host the scripts generated by Google Analytics and especially Tag Manager on the executing server, rather than fetching them client side, through Google's script block?
The goal is to avoid any dependencies on external scripts.
I understand it is not Google's recommendation to host neither analytics, nor tag manager locally, but is it possible to do so?
As I understand, tag manager works, by embedding a local script like so:
<!-- 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);
})(window,document,'script','dataLayer','YOUR-GTM-CODE');</script>
<!-- End Google Tag Manager -->
When this executes client side, it fetches a newly generated script (https://www.googletagmanager.com/gtm.js?id=YOUR-CODE), containing any new tags or triggers your editors have added to the container since last publish.
Apart from losing new tag manager features, and newly generated tags, will this work?
Otherwise that would indicate that the GTM container isn't being loaded at all. If it does show up, make sure that your tags have appropriate triggers so that they are instructed to fire. But the TL;DR - Yes, you can use GTM on "localhost".
Place the <script> code snippet in the <head> of your web page's HTML output, preferably as close to the opening <head> tag as possible, but below any dataLayer declarations.
To start collecting data, you need to put the Google tag in the code of your website. The Google tag must be on every page that has data you want to collect.
But it looks like Google Tag Manager isn't going away anytime soon: it's very popular, and the number of free and paid GTM resources is also constantly increasing. Also, if you're stuck with GTM, you can always get help in various places, e.g. GTM subreddit, GTM community on Facebook.
Nobody except the developers of these tags can answer this question with 100% guarantee. I’ll just outline the pitfalls you might face besides missing versions updates.
A few more notes to consider:
Finally, if this is really necessary do your best to make sure it would work in all possible environments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With