Home » Analytics » How to install Google Tag Manager on WordPress

How to install Google Tag Manager on WordPress

How to Install Google Tag Manager on WordPress

This is a practical guide for anyone who wants to install Google Tag Manager on WordPress. For those unfamiliar, GTM is a tag manager (from Google) that makes life easier for any developer, marketer or website owner. I will cover the two main methods of installing GTM on WordPress: (1) using a plugin and (2) editing the website template files. Come on!

If you don't already have a Google Tag Manager account, I suggest reading this article in its entirety. If you already have an account skip to the second step.

Creating a Google Tag Manager (GTM) account

Time required for this implementation: 2 minutes.

How to create a Google Tag Manager account

  • Providing information

    Go to the Tag Manager and click on the “Free Trial” button. Enter your Google credentials.

  • Creating the account

    In the upper right corner click on the “Create Account” button.

  • Configuring the application

    Then enter the account name, country, URL and where you want to use the container (Web, iOS, Android or AMP). As soon as you inform this data, click on “Create”.

  • Receiving the code

    You will now receive the codes and instructions for installing the tag and also a code to install the tag

Read too: “How to install Google Analytics on WordPress using a plugin”

Installing Google Tag Manager on your website

If you did not copy the codes provided when creating the account / container, enter your container and click on the ID shown at the top of the page:

Google Tag Manager installation code
Google Tag Manager installation code

The installation of these codes on the website can be done in two ways: (1) via the WordPress plugin or, (2) by editing the codes of the template used.

Before choosing one of the ways, keep in mind:

  • If you have the necessary permissions to configure in the chosen way (some security plugins can prevent the direct editing of template files for example).
  • How the site is maintained (if you do the maintenance or if a team of professionals takes care of it for you).
  • What other features do you want to implement with Google Tag Manager on your WordPress site (custom dimensions in GA, Google Optimize, etc.).

Installing Google Tag Manager on WordPress using a plugin

One of the great advantages of using a CMS like WordPress is the possibility to add functionality through modules, in WordPress called plugins.

Probably the best (and what I recommend) plugin for adding GTM to your WordPress site is the “DuracellTomi Google Tag Manager for WordPress”. Its installation is like any other plugin:

  1. Log in to your administrative panel.
  2. Go to Plugins> Add new.
  3. Look for "Google Tag Manager".
  4. Click "Install" on the plugin DuracellTomi Google Tag Manager for WordPress.
  5. Go to Settings> Google Tag Manager and enter the code for your GTM container in the appropriate field:
GTM configuration for WordPress
GTM configuration for WordPress

Using the plugin is the safest method for you to insert GTM to your website. Still, depending on the settings of your site, the quality of your theme code and the plugins used, there can be setbacks.

The script is added correctly to your site. It is essential for the functioning of the GTM on the website.

The script is an iframe snippet that acts as a replacement for users with JavaScript disabled (very small number of users). Because the WP does not have a hook for inserting custom code in the tag , by default it is added to the footer. This is not ideal because it reduces the likelihood of a tag being fired. It will still work but only after the entire page has loaded.

If you need the tag is fired at the correct location, you can choose a custom method of injecting the tag.

On my website the method Codeless Injection, but I make sure that my theme is aligned with this type of injection of the GTM code.

To ensure that the chosen injection method is working, perform tests on the main browsers.

Advantages of this method:

  • This method automatically activates multiple dataLayer variables that would only be available with a lot of customization. With these active variables it is possible, for example, to extract data for GA such as author, year of publication, type of user, etc.
  • In the integrations tab you will find the possibility to integrate other features such as ContactForm 7, WooCommerce and AMP.
  • In addition, you can inject Google Optimize's Page Hiding Snippet to run your experiments more safely.

Installing Google Tag Manager on WordPress by editing the template

Before making any changes to your theme, make sure you have the knowledge to do so. My suggestion is to avoid making changes to your template files. If you choose this method try to use the best practices, adopting a child theme so that your changes are not lost when your parent theme is updated.

Here's what you need to do:

In the administrative panel go to Appearance> Theme editor:

Editing WP themes

Select the theme used and insert the GTM tags in the appropriate places:

WordPress Theme Editor
WordPress Theme Editor

Click "Update file" and you are ready to use GTM.

Read too: "How to install Google Analytics using Google Tag Manager

Testing the GTM installation

After the installation phase, let's check if the chosen method was implemented correctly.

There are a few ways for you to test that your GTM has been installed correctly. My recommendation is that you use the following two methods to ensure that everything is right.

Method 1: through the page source code

Go to your website, right-click on the page, then click on “View page source code”. A new tab will open with your page's source code. Something like this:

GTM on the website
Source code of a page with GTM installed via plugin

Check that both GTM tags are implemented. Test on all pages to ensure it is implemented correctly.

Method 2: using Google Tag Assistant

Google offers an extension that can be added to your browser for quick checking of implemented tags, the Tag Assistant.

Install the extension. Access your website and click on the extension. It will display the implemented tags.

Google Tag Assistant
Tag Assistant - site with GTM tag implemented

If your Google Tag Manager tag is ok you can start registering and firing tags (Google Analytics, Hotjar, Facebook Pixel, etc.) within GTM.

Now it's up to you! What method did you use to insert GTM on your WordPress site? What tags do you use or intend to use? Got some doubt or have any tips to share?

Keep reading: "Digital Marketing Metrics: Which Are Important?

Keep reading: "Marketing metrics: partner metrics"

About the author

Free tips to optimize your website!
  • Get weekly tips on SEO, analytics and WordPress.
  • Digital strategies and insights to improve your conversions.