• Categories
    • Tutorials
    • Beginners Guide
    • WordPress News
    • WordPress Security
    • Best WordPress Plugins
    • WordPress Themes
    • Product Reviews
    • WP Tips & Tricks
  • Guides
    • Start a Blog
    • Make a Website
    • WordPress Hosting
  • WordPress Hosting
    • A2 Hosting
    • HostGator
    • Bluehost
    • Cloudways
  • Managed Hosting
    • WPEngine
    • Rocket.net
    • WPX
    • Kinsta
  • Coupons
    • WPEngine
    • Flywheel
    • Cloudways
    • A2 Hosting
    • WPX Hosting
WordPress Tutorials

How To Add Google Tag Manager To WordPress And Create Your First Tag

Last Updated on: June 23, 2018 Colin Newcomer 3 Comments

How To Add Google Tag Manager To WordPress And Create Your First Tag

Want to add Google Tag Manager to WordPress?

Google Tag Manager has a ton of benefits for WordPress sites. It helps you add and manage all the various scripts you use on your site. For example, instead of needing to manually add code for services like:

  • Google Analytics
  • Event tracking
  • Google Optimize

You can just manage everything through Google Tag Manager!

If you find yourself often adding various scripts to your WordPress site, Google Tag Manager is going to be a lot more convenient for you. And once you get the hang of it, you can even start using it to collect more actionable data to inform your marketing efforts.

In this post, I’ll show you step-by-step how to install Google Tag Manager on your WordPress site, including where to add the code.

Then, I’ll give you a quick guide for how you can publish your first tag and make sure it’s working.

Let’s dive in!

Step 1: Sign Up For A Google Tag Manager Account

If you haven’t already, the first thing you need to do is sign up for a free Google Tag Manager account.

You can do that by heading here.

Once you sign up, you should be in the Add a New Account interface. Give your company a name:

sign up for gtm

Then, in the Setup Container section, enter your website’s name in the Container name field and choose Web:

configuire container

Once you accept Google’s Terms of Service, Google should take you to the Google Tag Manager interface and show you two code snippets. Keep this window open because you’ll need to add both of these code snippets to your WordPress site in the next section:

google tag manager code snippets

Step 2: Add Google Tag Manager Code Snippets To Your Site

This is the one part that’s kind of tricky. Previously, you only had to add one code snippet to your theme’s <head> section, but now Google Tag Manager wants you to add two snippets:

  • The first one goes in your <head> section
  • The second one goes right after the opening <body> tag

Beyond directly editing your child theme, WordPress doesn’t give you an easy way to insert code after the <body> tag, and each theme works a little differently so I can’t give you a tutorial that applies to all themes.

So:

  • If you already feel comfortable editing your child theme’s files directly, you can just do that.
  • If you don’t feel comfortable working directly with your theme’s files, I’ll show you two different methods that you can use – a beginner-friendly plugin and a simplified code method.

Option 1: Use Head, Footer and Post Injections

If you’re ok with dedicating a plugin to Google Tag Manager, the easiest way to add it is using the free Head, Footer and Post Injections plugin.

To get started, install and activate this free plugin. Then, go to Settings → Header and Footer in your WordPress dashboard to access the plugin’s interface.

Now:

  • Paste the first Google Tag Manager code snippet into the ON EVERY PAGE box in the <HEAD> PAGE SECTION INJECTION section
  • Paste the second Google Tag Manager code snippet into the DESKTOP* box in the AFTER THE <BODY> TAG section (don’t worry – the code snippet will still load on mobile. Head, Footer, and Post Injections just makes it possible to use separate code snippets if you check the mobile box)

It should look like this:

how to add google tag manager to wordpress - where to put code

Make sure to save your changes and you’re all done!

Option 2: Use A Functions.php Code Snippet

Let me lead by saying that this method is technically not 100% optimal. It works fine for most sites, but I’ll explain what I mean after I show you what to do.

To use it, all you need to do is add this code snippet to your child theme’sfunctions.php file:

add_action('wp_head', 'gtm_head_code');
Function gtm_head_code(){
?>
FIRST_SCRIPT_FROM_GTM_INTERFACE
<?php
}
add_action('wp_footer', 'gtm_body_code');
Function gtm_body_code(){
?>
SECOND_SCRIPT_FROM_GTM_INTERFACE
<?php
}

Make sure to replace the placeholders with the actual code snippets.

So why isn’t this method 100% optimal?

Because this method puts the second code snippet in the footer, rather than after the opening <body> tag, your tag might not fire if a visitor doesn’t completely load your page (which is rare, but possible). That’s the reason Google recommends you add it as high up in your site’s code as possible.

But for most sites? This method is totally fine.

Step 3: Test To Make Sure Your Snippets Are Working

To make sure you properly installed Google Tag Manager:

  • Go to the free GA Checker tool
  • Enter your website’s URL
  • Click Check Your Site

Go to the Tag Manager tab of the results and look for the green checkbox in the Tag Manager column:

test tag manager

If you see it – congrats! You properly installed the Google Tag Manager scripts on your WordPress site.

Now, I’ll quickly go through how to use Google Tag Manager to create your first tag.

Step 4: Create Your First Tag

Once you’ve added the code snippets to your site, you can go back to the Google Tag Manager interface and create your first tag.

A “tag” is basically a specific script that you want to insert into your site with Google Tag Manager.

To get started, create a New Tag in your Google Tag Manager dashboard:

create tag

By clicking on Tag Configuration, you can choose what type of tag to create. Google includes all kinds of pre-built options for stuff like Google Analytics, Google Optimize, and lots of third-party services.

But you can also use the Custom HTML or Custom Image tags to insert any client-side code:

choose tag type

Once you choose your Tag Type, you’ll need to configure it following the settings.

Then, you can click on the Triggering section to choose when to “fire” your tag.

The default is All Pages, but you can also get a lot more targeted if you want by clicking on the + icon:

trigger

Once you finish setting things up, click Save.

Step 5: Publish Your Container

Now, all you need to do to make your tags live is publish your Container.

To do that, click on the SUBMIT button in your Google Tag Manager interface:

submit

Then, enter a Version Name and Version Description. I recommend that you make these as detailed as possible to help with version control later on. That is, explain exactly which tags you’ve added and what they do.

Then, click PUBLISH:

publish container

And that’s it! You just published your first tag.

How To Test If Individual Tags Are Firing

If you want to make sure the individual tags in your container are firing, Google offers a free browser extension for Chrome called Tag Assistant.

Resources To Help You Become A Google Tag Manager Pro

At this point, you’ve successfully added Google Tag Manager to WordPress. But Google Tag Manager is pretty deep in functionality and explaining the huge number of interface options goes beyond the scope of this post.

So – now that you have Google Tag Manager installed, you can learn a whole lot more about the interface in this Moz article.

And for more related reading on some of the tags you can implement in Google Tag Manager, check out our posts on Google Analytics and WooCommerce Google Analytics goals.

+ Share
Disclosure

Colin Newcomer

Colin Newcomer is a WordPress writer for WPKube. He uses WordPress more often than any sane person should.

Related Posts

Back to all articles
  • How to Increase the Memory Limit in WordPress

    How to Increase the Memory Limit in WordPress

  • What is WordPress? A Beginner's Guide!

    What is WordPress? What Can it do & Is it Right for You? A Beginner’s Guide

  • How to Use Git to Push Your Local Site Live

    How to Use Git to Push Your Local Site Live

Coupons

View more deals
  • Recipe Card Blocks Coupon
    15% OFF

    Recipe Card Blocks Coupon

    Running a cooking or food website can be fun (and tasty) – but
    Get This Deal
  • WP 2FA Coupon
    20% OFF

    WP 2FA Coupon

    Security should be at the forefront of all site owner’s min
    Get This Deal
  • Themskingdom Coupon
    20% OFF

    ThemesKingdom Coupon

    First impressions count. As such, you’ll want a WordPress t
    Get This Deal
3 Comments Leave a Reply
  1. Gil says

    May 23, 2019 at 2:52 pm

    After checking so many alternatives – the php option (options 2) seems to be the only one that worked for me. Thanks!

    Reply
  2. Henry Garcia says

    June 4, 2019 at 9:21 pm

    This was great! It helped me a lot, I used the plugin option.

    Reply
  3. Mayur Gaikwad says

    August 13, 2019 at 10:02 am

    Amazing information that helped me set GA tags on my new website.

    Reply

Leave a Reply Cancel reply

Full Disclosure This post may contain affiliate links, meaning that if you click on one of the links and purchase an item, we may receive a commission (at no additional cost to you). All opinions are our own and we do not accept payments for positive reviews.

THE BEST OF WPKUBE

Some of the best content we have published so far.

BEGINNER GUIDES & REVIEWS

18 Best Cheap WordPress Hosting Providers in 2023 (From $1.99)
210 Best WordPress Hosting Options for 2023 (Pros & Cons)
38 Best Managed WordPress Hosting Providers for 2023 Compared
45 Best WooCommerce Hosting Providers Compared in 2023 (All Budgets)
5Top 9 Landing Page Plugins for WordPress (2023)
69 Best List Building Plugins for WordPress In 2023
7How to Fix the 500 Internal Server Error on Your WordPress Website
8Thrive Themes Review: A Look At The Full Membership
9Beaver Builder Review: Is it The Best Page Builder Plugin for WordPress (2023)?
10OptimizePress Review: Create Landing Pages with Ease
11How to Make a Website: Complete Beginner’s Guide
12Top 22 Best Free Stock Photo Resources For Your Site
1317 of the Best Google Fonts for 2023 (And How to Use Them in WordPress)
14How to Start a Blog in 2022 (Step by Step Guide)
15How To Fix ‘503 Service Unavailable’ WordPress Error
1611 Best Contact Form Plugins for WordPress in 2023
17How to Add a Custom Logo to Your WordPress Site
18How to Fix Error Establishing a Database Connection in WordPress

WPX Hosting: 50% OFF

Save 50% on WPX Hosting using our exclusive coupon code.

Get this Deal

Flywheel(our review)

Our Newsletter

Get awesome content delivered straight to your inbox.

Thank you!

You have successfully joined our subscriber list.

.
Featured In Forbes Huffpost Entrepreneur SEJ

About WPKube

WPKube is an online WordPress resource which focuses on WordPress tutorials, How-to’s, guides, plugins, news, and more. We aim to provide the most comprehensive beginner’s guides to anything about WordPress — from installing plugins, themes, automated installs and setups, to creating and setting up pages for your website.

We have over 500+ tutorials, guides, product reviews, tips, and tricks about WordPress. Founded by Devesh Sharma, the main goal of this site is to provide useful information on anything and everything WordPress.

Twitter Facebook

Useful Links

  • Behind the Scenes
  • Beginner Guides
  • WordPress Hosting
  • WooCommerce Themes
  • MeridianThemes
  • Exclusive WordPress Deals
View All Guides »

Reviews

  • WPEngine 33% OFF
  • Thrive Leads
  • Flywheel 33% OFF
  • Divi Theme 20% OFF
  • Thrive Architect
  • Elegant Themes
Reviews »

Deals

  • InMotion Hosting
  • LifterLMS Coupon
  • LiquidWeb Coupon
  • WPEngine Coupon
  • A2 Hosting
  • FloThemes
More Deals »
© Copyright 2023 WPKube ® All Rights Reserved.
  • Contact
  • Site Terms
  • Disclosure
  • Privacy Policy