What's WP
Our everything is about WordPress - best choice of WordPress users!
How to Set Up and Use Google Tag Manager in WordPress

How to Set Up and Use Google Tag Manager in WordPress

Google Tag Manager is free service that offers an easy way for adding and managing tracking code and other third-party scripts and tags on Your WordPress site. With this tool, you don’t need to edit the code of your theme manually every time you want to insert or remove code snippets, which saves time and trouble.

Still feel a little bit confused and don’t know whether you need it? Well, in below, we will provide more details about the benefits and show you how to set up and use Google Tag Manager in WordPress.

Google Tag Manager & Its Benefits

Traditionally, when you integrate services like Google Analytics and Google AdWords with your site, you have to add separate pieces of code in your template files for each one. And when you do not need them, you will need to remove the code manually. These tasks are not hard for experienced users, but beginners might corrupt the files due to a lack of knowledge about coding. Besides, too many code pieces are annoying and hard-to-manage even for developers.

This is why Google Tag Manager is created. When this tool is integrated with your site, you no longer need to touch the template files when managing third-party scripts. Instead, you add, manage and remove the tags in a single dashboard which is well organized.

Google Tag Manager supports a wide range of tags including Google services like Google Analytics and Google AdWords, and third-party services like ClickTale and AdRoll. Besides, you can also create your own tracking with custom HTML.

The benefits of using Google Tag Manager are mainly:

  • Centralized tag management. Within a simple interface, you can add/remove tags and see which script is running on which pages.
  • Easy access management. You can give your team members access to Google Tag Manager and allow them to add tags without accessing your website’s code.
  • Version rollback. You can easily rollback to the previous working version when changes cause trouble.
  • Centralized reports. Google Tag Manager puts all the reports together, which makes it easier to understand and analyze the events on your site.
  • Faster page loads. Reducing the number of scripts is an effective way for speeding up WordPress sites. This is what Google Tag Manager can achieve by separating all the scripts from your site.

Set up Google Tag Manager in WordPress

The entire process is easy and can be accomplished within 10 minutes. But before following any step, you should note that the tutorial below is designed for setting up Google Tag Manager on a self-hosted WordPress site.

Create an account for Google Tag Manager

Assumed that you have already had a Google account, then you can visit the offical website of Google Tag Manager and log in with your account. After logging in successfully, you are directed to the new account setup page. Enter an account name and click on the “Continue” button.

Set up Account

Now you are required to set up a container. The container can be a website or an app on IOS or Android. Since we are working on a WordPress site, we will define the container name to be our site’s domain, and then choose “Web”. You are able to create multiple containers for your account.

Set up Container

The system then shows you a Terms of Service agreement and tells you to choose a language. Make your own selection of the language and agree to the TOS by clicking on the “Yes” button.

Terms of Service Agreement

Your account and the container are created automatically. When you land on the container dashboard, you will see a popup window showing the following tracking code and asking you to install Google Tag Manager on your site immediately.

Google Tag Manager Tracking Code

Do not feel nervous about the code. You can just leave it alone because we will introduce an easier way for adding the tool to your site, without using this piece of code. Closing the popup window, you will see a dashboard like this.

Container Dashboard

Add Google Tag Manager to you site

There are two ways for doing this – manually editing the template or using a plugin. We are going to introduce the latter way because a DuracellTomi’s plugin named Google Tag Manager for WordPress works very well and offers many additional options and marketing features.

Another benefit of using a plugin is that you do not need to insert the tracking code again when you change the theme or the core template files are updated. Also, DuracellTomi’s plugin can integrate with Contact Form 7 and WooCommerce.

To add Google Tag Manager, you should first log into your WordPress site and install the plugin mentioned above.

Install Google Tag Manager for WordPress Plugin

Upon activation, find the plugin in the plugin list and click on the “Settings” link. You can see these options.

Plugin Settings

Now you need to go back to Google Tag Manager container dashboard to find the GTM ID. You can see the location of the ID in the following screenshot. Copy the ID into the plugin options.


To get Google Tag Manager running, the plugin will also place a container code into the template. This can be done by the plugin itself as long as you keep the default configuration of the “Container code placement”. If there is a problem with the option or you want to place the container code after the opening <body> tag just as suggested by Google, you can select “Custom”.

Container Code Placement

For the custom placement, you have to manually add the code specified in the screenshot above into your template file. You can do this by navigating to Appearance > Editor, opening the Header file (header.php), and then inserting the code below the line starting with “<body”.

Edit Template File

Save the changes, and now you have successfully integrated Google Tag Manager with your WordPress site.

How to Use Google Tag Manager

As you have properly set up Google Tag Manager, you should be curious about how to use it to manage tags and scripts. In the following part, we will make an example by explaining how to add Google Analytics to your site with Google Tag Manager.

Get Google Analytics tracking ID

First of all, you can follow this Google Analytics tutorial to create an account and make necessary configurations. When the account is set up, open the “Admin” tab, and expand the “Tracking Info” under “Property”.

Tracking Info

Clicking on “Tracking Code”, you will get the tracking code as well as the UA tracking ID. The tracking ID is used to identify your website. You should copy it for future use.

Tracking ID

Add a tag in Google Tag Manager

Log into Google Tag Manager and navigate to the container dashboard. Click on “New Tag”.

New Tag

You now should choose the product. For our example, Google Analytics is required.

Choose Product

After selecting Google Analytics, you are asked to choose a tag type between Universal Analytics and Classic Google Analytics. Select the former one.

Choose a Tag Type

In the third step, fill in the tracking ID you got before, select “Page View” from the drop-down for “Track Type”, and then click on “Continue”. You don’t have to touch other settings.

Configure Tag

For the last step, choose to fire your tag on “All Pages”, and then click on the “Create Tag” button. Your new tag will be created immediately.

Fire on All Pages

Publish the container

Tags do not go alive unless their container is published. Therefore, to make Google Analytics working, you have to publish the container first. You can do this by clicking on the “Publish” button and choosing to publish the container now. Besides, you can also preview and debug the changes before applying them to your site.

Publish Container

That’s all. You have added Google Analytics to your site without editing any code of your template. Integrating other scripts is the same easy. You can also take some time exploring more features of Google Tag Manager.


Joyce is a professional writer & SEOer who loves trying new things and sharing the experience through blogging. She loves clean design, playing with different WordPress themes, SEO, etc. Now she is very struggle with purchasing a bubbling apartment in downtown. You can help her by clicking our ADs or making a purchase via our links ;-)


Want to Learn More About WordPress?

Get Our Free Themes, Plugins, Support, SEO Tips, and Other Tutorials!

Email *