Google Tag Manager WordPress Installation Guide

In this article I will show you how to correctly install Google Tag Manager on your WordPress Website.

Follow the steps below:

Step-1: Understand what Google Tag Manager really is. In a nutshell it is a free online tool which is used to deploy and manage various tags on your website. Google Tag Manager (GTM) is not the same as ‘Google Analytics’ (GA). So Google Analytics is not automatically installed on your website just because you installed GTM.

To learn more about Google Tag Manager and how it is different from Google Analytics, read this article: Google Tag Manager Tutorial for Beginners

Step-2: Get an ‘Admin’ access of the wordpress website where you want to install GTM.

Step-3: Login to your wordpress Admin panel and then navigate to ‘Appearance’ > ‘Editor’:

Note: If the wordpress Appearance Editor option is missing then it means either you do not have the ‘admin’ access or because of some security settings, the option is hidden.

Step-4: Look at the various template files on the right hand side to get an idea of what is available to you in your website theme:

A wordpress theme is made up of several template files like: header.php, footer.php, , sidebar.php, functions.php etc. All of these template files work together to create your website design and functionality. The template files make customization possible on your wordpress website. The more template files your theme has got, the more customization you can do on your website. The name and number of template files vary from theme to theme.

So some theme may have got ‘header.php’ file and some theme may not have any such file. It is also possible that some themes refer to ‘header.php’ file by some other file name. In some themes, it is possible to add a code both in the head and body section of a HTML document via headers.php file while in some other themes it may not possible to add any code in the body section of a HTML document via header.php. It all depends upon how your theme has been coded.

That’s is why it is important that before you add/edit any code to your wordpress website, get familiar with your theme template files esp. the template file which is responsible for generating headers and navigation on your website.

In most cases the wordpress template file which generate headers and navigation is named ‘header.php’. Through this file you can make changes to the head section (<head>…..</head>) of each web page on your website. In many themes, this file also let you add code immediately after the opening body tag (<body>).

If you are using a wordpress theme framework (like ‘Genesis’) then most likely you use two themes instead of one. These two themes are called the parent theme and the child theme.

The parent theme contains all of your website’s core functionality. The child theme inherits its functionality from the parent theme and is used to add custom styling options. So use the child theme to do whatever customisation you want to do (like adding the GTM container code) on your website. Leave the parent theme intact.

The advantage of using a wordpress theme framework is that you can easily update your theme without the risk of losing custom styling. Your customisation won’t automatically disappear with next WordPress upgrade.

To learn more about how and which template files work together to create your wordpress website design and functionality, read this article: Understanding WordPress Website Architecture

Step-5: Find the name and location of the template file through which you can add a piece of code in the head section (<head>…</head>) of each web page on your website. Most likely it will be ‘header.php’ template file. But it could also be something else.

Step-6: Find the name and location of the template file through which you can add a piece of code immediately after the opening body tag (<body>). Most likely it will be ‘header.php’ template file. But it could also be something else.

For example if you use genesis framework, like I do then there is no easy way to add a piece of code immediately after the opening body tag. So I asked my child theme developer to provide me a way to add a code immediately after the opening body tag. He created the function “_genesis_before_js_callback” in the functions.php file and then asked me to add my code there:

_genesis_before_js_callback(){

/*

* Add your custom js code here;

*/

?>

<script> </script>

<?php

}

You may need to come up with such workaround. Your theme developer can help here.

Note: If for some reason you can not find the name and location of the template files through which you can add a piece of code in the head section (<head>…</head>) and a piece of code immediately after the opening body tag (<body>) on each page of your website then contact your theme developer.

Step-8: Navigate to https://tagmanager.google.com and then login, using your Google username and password.

Step-9: Click on the ‘Create Account’ link:

Step-10: Enter your account name (you can use your company name as account name) and then click on the ‘Continue’ button:

Step-11: Enter the ‘container name’ (use your website name as container name) and select ‘Web’ under ‘Where to use Container’:

Step-12: Click on the ‘Create’ button.

Step-13: Accept ‘Google Tag Manager Terms of Service Agreement’ by clicking on the ‘Yes’ button. You will then see the ‘Google Tag Manager Installation Code’:

This code is made of up of two parts. The first part goes into the head section of your web pages and the second part goes into the body section.

NoteIf you already have GTM account then just click on the container ID to see the GTM installation code:

Step-14: Copy the first part of the GTM installation code:

and paste it as high as possible, in the head section (<head>..</head>) of your header.php (or some other equivalent template file) via your wordpress admin panel:

Note: Take a backup of your theme template file before you make changes to it. So if something goes wrong, you can easily revert back to the last known good configuration.

Step-15: Click on the ‘Update File’ button to save the changes made to your theme file.

Step-16: Copy the second part of the GTM installation code:

and paste it in the template file which allow you to add the code immediately after the opening body tag (<body>):

Note: Take a backup of your theme template file before you make changes to it. So if something goes wrong, you can easily revert back to the last known good configuration.

Step-17: Click on the ‘Update File’ button to save the changes made to your theme file.

Step-18: Navigate back to your GTM account and then click on the ‘Submit’ button:

Step-19: Enter version name and then click on the ‘Publish’ button to publish your container:

Step-20: Click on the ‘Workspace’ link (in the top navigation) and then click on the ‘Preview’ button:

Step-21: Navigate to one of the web page of your website. You should now see the GTM debugger window at the bottom of the page:

If you see the debugger window, then it means the Google Tag Manager is installed on your website.

It is important to remember that at this stage you have not yet installed Google Analytics on your website. You have installed only the GTM container tag on your website. In order to install Google Analytics on your website, you would first need to create a tag in GTM which fires Google Analytics pageview on all the pages of your website. Then you would need to preview and publish your container.

To learn more about how to install Google Analytics on your website via GTM, check the section ‘Setting up Google Analytics via Google Tag Manager’ of the article ‘Google Tag Manager Implementation & deployment Guide

Step-22: Navigate back to your GTM account and then click on the ‘Leave Preview Mode’ link:

That’s how you can install Google Tag Manager on your wordpress website.

Installing Google Tag Manager on WordPress website via Plugin

I am not a big fan of using plugins and use them only when it is absolutely necessary. The biggest downside of using a plugin is the lack of control on the code, placed on your website by the plugin. Other minor issue is that use of plugins negatively impact your wordpress website speed. So I try to minimise the use of plugins, wherever I can.

You can also install GTM on your wordpress website via a plugin. But you may still need to make some code changes in your wordpress template file(s).  The advantage of using a plugin is that, you can take advantage of the added functionality provide by the plugin.

I find the DuracellTomi’s Google Tag Manager for WordPress plugin quite useful. Following are the various advantages of using this plugin:

#1 If you are using a genesis child theme then you can install GTM on your website without making any code changes to your template file(s). Just add your container ID and select ‘custom’ next to ‘container code placement’, to install GTM on your website:

However after the installation, test whether this plugin is compatible with your website theme. If the plugin is not compatible with your website theme then you can either uninstall it or you can ask your theme developer to make your website theme compatible with the plugin.

#2  You can easily push lot of information (related to: blog post, site search, visitors, browser etc) into data layer and then later with the help of data layer variables you can send this information to Google Analytics.

#3 You can enable scroll tracking and/or video tracking.

#4 You can blacklist various tags and variables.

#5 If you use woocommerce then you can set up ecommerce tracking or enhanced ecommerce tracking on your wordpress website.

Note: There are many plugins available through which you can install GTM on your wordpress website. You can search for them in the ‘Plugins’ section of your wordpress admin panel.

Other articles on WordPress

Announcement about my books

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Himanshu Sharma

Certified web analyst and founder of OptimizeSmart.com

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues. If you have any questions or comments please contact me.

  • Over eleven years' experience in SEO, PPC and web analytics
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of OptimizeSmart.com and EventEducation.com

I am also the author of three books:

error: Content is protected !!