How to install Google Tag Manager to WordPress [FAST & EASY]

This guide has everything you need to know about adding Google Tag Manager to WordPress.

And here's the kicker:

More...

Installing GTM correctly now will make your life comfortable in the long run because it can cause total success or total mayhem to your setup. And nobody wants chaos.

Let’s break down exactly how to add Google Tag Manager to WordPress effectively and painlessly via two simple ways. And the best part is that everything is going to take no more than 5 minutes.

Sound good? Let’s dive right in…

The only guide you will need to install #GTM to #WordPress A 5-minute plan and two techniques

Click to Tweet

Step #1: Create a Tag Manager account (if you haven’t already)

Since you are here, you probably have an account so just skip to the next Step.

But if you need to set up the free account, here’s what you do:

1. Go to Tag Manager and click the "Start for free" button. Sign in with your Google credentials.

2. From the main dashboard, click on the top right button "Create Account."

3. Next, input your account name (company or domain), country, and website URL, as well as where you want to use it. Web in our situation. When you’re finished, click the blue "Create" button.

4. Now, you’ll be given the codes and instructions to include one code high in the <head> of your page, and the other after the opening <body> tag.

Step #2: Implement Google Tag Manager code to your website

If you need to go back to get the scripts just click on Google Tag Manager ID which you can find on the top right corner. After you click on it a window will pop-up.

Now, adding the scripts to a WordPress website can be done by using a plugin or by editing the theme files.

But there is a catch:

The way WordPress works is that you need access to edit files or install a plugin. Make sure this is something that you can do before going forward. 

Method #1: Use a plugin to add Tag Manager

Content management systems like WordPress have the availability to extend their functionality by installing plugins.

One that I can recommend is DuracellTomi Google Tag Manager for WordPress by Tamas Geiger. Installing it is very easy:
  • 1
    Log in to your WordPress admin panel.
  • 2
    Go to Plugins / Add new.
  • 3
    Search for "Google Tag Manager."
  • 4
    Click on "Install now" in the search results next to "DuracellTomi’s Google Tag Manager for WordPress."
  • 5
    Now, go to Settings / Google Tag Manager and enter your GTM container ID.

Even if the plugin is a safer route, know the following about this method.

The <head> script is added correctly to your website because it is critical to enable all features of GTM.

The <body> script is an iframe snippet that acts as a fallback for users with JavaScript disabled. Because WordPress doesn’t have a hook to place custom code under the body tag, by default it is placed in the footer.

This is not ideal because it reduces the likelihood of the tag to be fired. It will still works, but only after the page was fully loaded.

If for your setup you definitely need the <body> script to be added in the respective tag, you can choose the custom injection method. The plugin uses a workaround. To be sure everything is running smooth, you need to check if this doesn’t mess up your website in multiple browsers.

Extra points when using GTM4WP

A great thing about using this plugin is that it comes with multiple dataLayer integrations usually available through customization.

For example, in the Basic tab, we can send the post date, author name or post title to the dataLayer. We can take these data points and transfer them to our analytics tool.

The Integration tab is something you probably need to check if you are using plugins such as ContactForm 7 or WooCommerce. It is handy if you want to utilize Google Analytics Enhanced E-Commerce Tracking capabilities because you don’t have to implement the dataLayer yourself.

Also, the plugin can inject the Google Optimize Page Hiding Snippet to make your experiments run smooth.

Method #2: Edit the theme files to install Tag Manager

It’s best practice to have a child theme for whatever customization you want to do to your theme. Like adding the GTM container code. You don’t want the changes to be overwritten when a new update becomes available for your parent theme.

Usually editing the theme's files is something that you should avoid. Talk to your websites developer to choose the best method.

Here is what you need to do (or what a developer would do):

Within WordPress, you can log into your dashboard, then go to Appearance.

Under Theme editor, you should have access to the theme files itself. Look for the theme header.php file and click on it.

Here you will find the head tag and the body tag. Let’s copy the first part of the code and place it beneath the opening head tag. The second script part needs to go beneath the opening body tag.

Now let’s update the files.

Step #3: Check if GTM is installed correctly

Marketers that succeed installing the latest version of Tag Manager on WordPress do two things very well:

First, they publish a version of the GTM container to initialize it. Second, they always test the implementation via multiple methods.

Now let’s see if you have any issues that might be hurting your site.

To do that, here are four ways to check:

Go to your website and look into your page source to see if the scripts are now placed in the head section of our HTML and beneath the opening body tag.

To do this, right click and look for the View page source option.  Now you could go through other pages and check whether it’s installed in the HTML, but we can also help ourselves with some tools.

The first tool is the Tag Assistant by Google. After you install it on your browser, click on the icon to open it. You should see that Google Tag Manager is installed.

Now you should go again through all the pages and see if it’s installed, but there is another trick.

Google Tag Manager has a preview and debug mode so that you have visual confirmation. You should see an interface that pops up.

Go through the pages and do a little bit of a spot check.

If you want to get more sophisticated or do an audit, then I would recommend a software such as Screaming Frog which you can configure to go through all the pages and check whether your Google Tag Manager code is installed. Just check the JavaScript option when crawling.

In most cases, by now you have successfully installed Google Tag Manager and are ready to deploy tags.


Now, Over To You…

I’d like to hear from you:

Which method from today’s guide did you use to add Google Tag Manager to WordPress?

What tags are you going to add?

Or maybe you’re not sure with what to start first.

Leave a comment to let me know.

Leave a Comment

avatar
 
smilegrinwinkmrgreenneutraltwistedarrowshockunamusedcooleviloopsrazzrollcryeeklolmadsadexclamationquestionideahmmbegwhewchucklesillyenvyshutmouth