Forum Discussion

snaffle's avatar
snaffle
Expert
11 years ago

Google Tag Manager

Hi there,

 

Just wondering if anybody has implemented Google Tag Manager code in to their Lithium skin rather than just straight Google Analytics code?

 

The documentation recommends that the code be inserted directly after the opening <body> tag, but obviously we don't quite have access to that specific location through Studio.

 

I'm wondering if adding it at the top of the "Page Header" section in Studio would work?

 

Thanks


Nathan

  • We've seen Google complaining about the GTM being inside certain elements other than <body>. You are correct that it's supposed to be just after the open <body> however we've not had any problems with it being right before the close </body>. I have seen mention online of people injecting the GTM script after <body> using JS which doesn't sound that great but would probably work.  

    • PaoloT's avatar
      PaoloT
      Lithium Alumni (Retired)

      This comes from the Google Analytics blog:

       

      Can the Google Tag Manager snippet be placed in <head>? How about in my footer?
      The recommended best practice is to have the Google Tag Manager snippet at the top of the <body> to maximize data collection, but some clients may find it easier to implement the Container snippet elsewhere in the in the page, like the footer. 
      
      Do not place the Google Tag Manager snippet in <head> (for the IT folks: this is because there is an iframe in the <noscript> case, which can have unpredictable results in some browsers). 
      
      No matter where you install the container snippet, you will need to make sure that this snippet of code is on every page of their site. Google Tag Manager will still work if you only deploy it on part of your site, but Google Tag Manager’s rule based system will only work on pages where the snippet is deployed. For more details, read our developer documents. 

      I think the best option is to install this in the Studio's Header section of your Skin.

       

      Thanks,