Written by The Jahia Team
 
Marketers
Sysadmins
   Estimated reading time:

What is the best way to embed the Google Tag Manager into my site?

Answer

To install the Google Tag Manager, you need to insert some code in all of your pages. A part has to be as high in the <head> of the page as possible, and the other immediately after the opening <body> tag.

You can do it directly in the main JSP of your template set, or you can use the module addStuff.

To install this module deploy it from the administration then activate the module on your site, go to edit mode and right-click on the site from the left panel, then go to Option and click on the "Add stuff in your HTML code (only for preview/live mode)".

 

Then you can copy the generated this snippet in the top of the HEAD (please use the real code from the GTA main site -> Admin -> Install Google Tag Manager). This looks like this:

<!-- 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-ID-HERE');</script>
<!-- End Google Tag Manager -->

and this code on the top of the BODY:

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

The AddStuff module only inserts the code in preview and live mode.

Related links