How to insert Google Tag Manager in global "before </body> custom code section

Hey guys,
Getting errors when trying to add the GTM snippet to the global custom code section. I had a similar issue adding a Quantcast snippet. The issue is that Webflow has an issue with ‘noscript’. The guys at Quantcast replaced the ‘noscript’ with some javascript (see below) and then it worked. I’m not a dev but if someone could take this methodology and apply it to the GTM snippet (and it works!) then we would have a workaround that keeps the GTM code in one place and applies it to all pages.

Here is the ‘noscript’ part of the Quantcast snippet:

<noscript>
<div style="display:none;">
<img src="//pixel.quantserve.com/pixel/p--aN266mkQpEH0.gif" border="0" height="1" width="1" alt="Quantcast"/>
</div>
</noscript>

Here is the javascript workaround that I got from Quantcast:

<script language="JavaScript">
<!--
document.writeln("<noscript>");
document.writeln("<div style=\"display:none;\">");
document.writeln("<img src=\"//pixel.quantserve.com/pixel/p--aN266mkQpEH0.gif\" border=\"0\" height=\"1\" width=\"1\" alt=\"Quantcast\"/>");
document.writeln("</div>");
document.writeln("</noscript>");
//-->
</script>

Here is the ‘noscript’ portion of the standard GTM snippet. If anyone can apply the same logic as the fix above I would be very thankful!

<noscript>
<iframe src="//www.googletagmanager.com/ns.html?id=GTM-KP738W"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

Thanks in advance!

Alfredo

Hi @alfredo have you tried using the embed component and adding that as the very last element on your page?

http://help.webflow.com/faq/how-to-use-the-embed-widget-to-add-custom-code-to-a-webpage

Hey @PixelGeek! Thanks so much for the response. I know about that option. I figured I would put it out there to the group because keeping the code in the global section adds some convenience over the page by page approach.

Good to have a fallback. :slight_smile:

Hi @alfredo, the noscript tag is not supported at the moment in the code editor, so it is best to leave that out if you plan to put the GTM tag in the Head of your site.

Also, the workaround that Quantcast gave does indeed work, but it results in doing nothing on the page, because it requires javascript for that code to run.

The noscript tag is used by the browser, when javascript is not available, so that workaround does nothing, it is not even executed on a browser that does not have javascript.

Hey @cyberdave! And here I thought those guys had been clever!?!? Thanks so much for that clear explanation. So does that mean that the only real option is to use the Embed component on every page of the site? Thanks in advance.

Alfredo

Hi @alfredo, according to google, they want the GTM snippet placed just after the body tag, which in Webflow means to put an Embed widget just under the root body element. Just put an embed there and paste in your snippet, minus the noscript tag, and then it should work fine.

If the site is updated with that setup, and you are able to share the link with me to the published URL (you may share this with me in a PM here in the need help pages) then I can verify if the tag is communicating to Google or not :slight_smile:

Hey @cyberdave, so I added the embed widget with the GTM code as you described. My site can be found at nysocialclub.com. I haven’t migrated my tags yet but perhaps you can still check. Also, how is this set up different than putting the snippet in the global custom code section? If the idea is to put tags in the GTM that are supposed to fire on all pages, will your suggested use of the embed component added to ONLY the landing page accomplish this? Just want to make sure. Please let me know. Thanks.

Alfredo

@cyberdave So I tried using the embed component to add the GTM code to every page. The issue now is that Google Tag Assistant is giving me an error regarding the GTM code:

<script> tag must not be included in a <div>

How can the GTM code be added ‘immediately’ inside the body tag of every page?

Thanks in advance.

Alfredo

3 Likes