Skip to main content

How to add Google Tag Manager to your Blogger template

2 min read

To implement Google Tag Manager in your Blogger template you need to add two snippets of code.

1. Copy the following JavaScript and paste it as close to the opening head tag as possible in your template, 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 -->

2. Copy the following snippet and paste it immediately after the opening body tag in your template, 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) -->

In blogger you will see the following error

Error parsing XML, line 10, column 43: The reference to entity "l" must end with the ';' delimiter.

Due to the way Blogger parses XML, this line of code needs to be amended:

j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=

ReplaceĀ &lĀ with:

Fix Google Tag Manager Blogger error

When you replace the code and save the template you will not get the error message.