How to implement Google Tag Manager?

Hi,

First, I’d like to say that I am a big fan of Grav and this Forum! I am a complete Newby but thanks to the great documentation and the posts here, I was able to create a pretty decent website without any prior knowledge.

Now, I would like to implement Google Tag Manager on the website. The GTM Quick Start Guide tells me to:

Copy the following JavaScript and paste it as close to the opening <head> tag as possible on every page of your website, replacing GTM-XXXX with your container ID:

<!-- 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','GTM-XXXX');</script>
<!-- End Google Tag Manager -->

And the same for another snippet which goes into the body:

Copy the following snippet and paste it immediately after the opening <body> tag on every page of your website, replacing GTM-XXXX with your container ID:

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

I have been reading into the Asset Manager but I am not sure if this is the right way to go. I would really appreciate a quick pointer on this.

How/where do I implement those two code snippets on the website? Through the Asset Manager or can I just put them in the “base.html.twig” right after the <head> and <body> tag?

Thank you very much for your help!

I would, as you have already outlined, put them into the base.html.twig. It’s the safest and fastest way to have it everywhere. Just make sure you are working on a child theme, so that any theme updates won’t overwrite your changes.

Thank you very much Andrass!