Manually installing tags on WordPress is very inefficient and time consuming.

And there’s always a possibility that you could end up breaking your site in the process and affecting your user’s experience.

In this post, I’ll show you how you can prevent that from happening by installing Google Tag Manager on WordPress.

How Google Tag Manager works

The most significant benefit of using Google Tag Manager is that it allows you to install tags on your website without having to rely on developers.

All you need to know are how the different components within the tag management system work.

These components include tags, containers, triggers, and variables.

1. Tags

Tags are pieces of code that enable you to integrate third-party products into your website.

For example, you might use a tag from Google Analytics to help you track visitors on your site and another from Google Ads to track conversions from your ad campaigns.

Google Tag Manager natively supports a wide range of Google and 3rd party tags, and you can also use custom tags to implement unsupported configurations.

2. Containers

All the tags you create in Google Tag Manager are stored inside a container.

You’ll need to install a couple of lines of code to your WordPress site to make your containers work.

3. Triggers

The tags that are added to your containers will also need to send information when something happens on your site.

For example, when someone clicks on a link or submits a form.

These independent events are known as triggers, and all tags need to have at least one trigger assigned to them.

4. Variables

Finally, triggers use values stored inside variables to determine what conditions need to exist before firing.

In Google Tag Manager, you’ll be able to identify a variable by its syntax: {{variable name}}.

They fall under two categories: built-in variables and user-defined variables.

Built-in variables are pre-created and can’t be modified. For example, the built-in variable {{url}} refers to the URL of the page currently loaded.

If you wanted your tag to fire on every page of your site, you would set a condition in Google Tag Manager where {{url}} matches RegEx: .*.

User-defined variables help you take things a step further by allowing you to define custom functions that aren’t covered by built-in variables.

Since this is a beginner’s guide to Google Tag Manager, I won’t go into too much detail on custom variables. We’ll explore them in more depth in further tutorials.

Getting Started with Google Tag Manager on WordPress

Now that you know the main parts of Google Tag Manager let’s move on to creating your Google Tag Manager account.

Double check that you’re using the latest version of WordPress and that you have a Google Analytics account (you’ll find out why in a minute).

Creating your Google Tag Manager account

Once you’ve setup your Google Analytics account, head over to the Google Tag Manager site and create your account using the same email.

When you login to Google Tag Manager for the first time, you’ll see the screen below. Click on Create Account.

Next, enter your account name, country, container name, and target platform. For this tutorial, let’s set the target platform to Web.

Once you’ve created your account, locate your site’s header.php file and add the code below right after the <head> tag. Be sure to replace GTM-XXXXXX with the Google Tag Manager ID that shows up in your account.

<!-- 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-XXXXXX');
</script> 
<!-- End Google Tag Manager -->

After that, paste the code below immediately after the opening <body> tag in your site’s header.php file.

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

If you can’t make changes to your header.php file, you can use a plugin to install Google Tag Manager to WordPress.

Once you’ve installed the plugin, enter your Google Tag Manager ID in the settings window and click on Save Changes.

Creating your first tag

By this point, you should have Google Tag Manager successfully added to your WordPress site, and you can start installing your first tag.

As I mentioned before, there are a ton of tags that we can add through Google Tag Manager.

But to keep things simple, let’s create a tag for your Google Analytics account — this will allow you to install your tracking code through Google Tag Manager’s interface rather than installing it manually on your site.

To get started, go to your Workspace and then click on Add a new tag.

Give your tag a name. For example, “GA – Pageview – All Pages.”

Click on the tag configuration box and select Google Analytics: Universal Analytics in the window that pops up.

Now click on the Select Settings Variable dropdown and then choose New Variable.

Now open a new tab and head over to your Google Analytics account.

Get your tracking code by clicking on Tracking Info under your website’s property.

Your tracking ID starts with the letters “UA.”

Go back to your Google Tag Manager tab and finish creating your Tracking ID variable.

To keep things simple, give your variable the same name as your Google Analytics Tracking ID.

Click Save when that’s done.

Once you’ve saved your variable, you’ll notice that it shows up in your tag configuration with the syntax {{UA-XXXXXXXX}}.

After adding your variable, click the “Triggering” box to choose your trigger.

You should see a trigger that says, “All Pages.”

That means that your tag will fire on all pages of your website.

Select the All Pages trigger and then save your newly created tag.

Testing your tag

Your tag is now set up.

But it’s always good practice to test things out before pushing anything to your live site.

To test your tag, click on the Preview button in your workspace.

Once you’re in preview mode, visit your website, and the box below should show up at the bottom of your browser window.

If you did everything right, you should see your tag in the summary section.

Now that everything’s working, you can leave preview mode and then click on Submit to activate your tag.

Give your tag configuration a name and description and then click on Publish.

And that’s all there is to it — you’ve successfully installed a tag on WordPress using Google Tag Manager.

Pretty cool, huh?

What’s Next

In future tutorials, I’ll cover some of the more advanced features of Google Tag Manager, including custom variables, content conversion tracking and data filtering.

For now, give yourself a pat on the back for switching to Google Tag Manager — you’ve made a great decision.

If you found this article useful, be sure to share it.

Author Profile

Jerome Okutho
Jerome Okutho
B2B SaaS and IT digital marketing specialist with experience in marketing automation, copywriting, and SEO.