WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Beginners Guide» How to Install and Setup Google Tag Manager in WordPress

How to Install and Setup Google Tag Manager in WordPress

Last updated on March 29th, 2019 by Editorial Staff
404 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Install and Setup Google Tag Manager in WordPress

Are you looking to setup Google Tag Manager in WordPress? Not sure if you need Google Tag Manager on your WordPress site? Don’t worry. In this article, we will show you how to properly install and setup Google Tag Manager in WordPress and explain the benefits.

What is Google Tag Manager?

Google Tag Manager

Often website owners need to add multiple code snippets to track their conversions, traffic, and gather other analytical data.

With Google Tag manager you can easily add and manage all of these scripts from a single dashboard.

There are built-in tag templates for Google Analytics, Adwords, DoubleClick, etc. Tag manager also works with several third party analytics and tracking platforms.

Apart from that, you can use custom HTML to add your own tracking or any other code that you want to add.

This saves you the time of adding and removing tags from your code and rather manage it from an easy dashboard. Not to mention, all of these scripts are loaded in one script.

Having said that, lets get started with Google Tag Manager.

For the sake of this article, we will show you how to add Google Analytics to your site using Google Tag Manager.

Video Tutorial

Subscribe to WPBeginner

If you don’t like the video or need more instructions, then continue reading.

Getting Started

It’s important to note that this guide is for self hosted WordPress.org sites (see the difference between WordPress.com and WordPress.org). If you don’t have a WordPress site, then please see our WordPress installation guide to create one.

First you will need to create a Google Analytics account for your website if you haven’t already done so. You can follow the instructions in our how to install Google Analytics in WordPress tutorial.

Follow the steps mentioned in the “how to signup for Google Analytics” section. Stop when you get the tracking code. Instead of adding tracking code directly in WordPress, we will be using the tag manager to do that.

Setting Up Google Tag Manager

Now that we are ready to add Google Analytics, the next step is to setup Google Tag Manager.

Visit the Google Tag Manager website and sign up using the same Google account you used with Google Analytics.

After login you will come to the add new account page. Simply provide a name for your account and click on the continue button.

Creating Google Tag Manager account

Now you need to add a container to your account. A container could be a website or an app on iOS or Android platforms. In this case we will use the web.

You can use your site’s domain for the container name. You can add multiple containers for each account. Once you’re done click on the create button to continue.

Creating a container

Google Tag Manager will now create your account with the container, and you will see your container dashboard. It would look something like this:

Container dashboard

Now your Google Tag Manager account is ready, so the next step is to add a new tag. You can do this by clicking on create new tag.

First you will have to choose a tag product. Currently there are 20+ integration templates available.

We will choose Google Analytics for now, but you can always add more tags and choose different products according to your needs. You can even click on custom HTML to add any other custom code snippets.

Choose Google Analytics as product for your tag

Once you choose Google Analytics, you will be asked to select between Universal Analytics or Classic Analytics. Choose universal analytics, and you will be asked to provide your analytics tracking ID.

This tracking ID is a special code that allows Google to identify your site. You can obtain this ID by logging into your Google Analytics account and visiting the Admin tab.

Select the account and property for your site and then click on tracking info to expand it. You will see the tracking code link.

Finding your Google Analytics tracking ID

Clicking on tracking code will bring you to the tracking code page and will also reveal your UA tracking ID.

UA tracking id in Google Analytics

Copy your UA tracking ID and paste it in Google Tag Manager. Under track type choose Page View and then click on the continue button.

Add tracking id

The tag configuration wizard will now ask you when to fire this tag. Select all pages and then click on the create button.

When to fire on the tag

Google Tag Manager will now show you a tracking code that you need to add into your WordPress site. You need to copy this code.

Tag manager code

Adding Tag Manager Code in WordPress

First thing you will need to do is install and activate Insert Headers and Footers plugin. Upon activation, you need to visit Settings » Insert Headers and Footers.

Add your Google Tag Manager code in WordPress
Paste your tag manager code in the header section and click on the save button to store your settings.

If you do not wish to install a plugin, then you can also add the Google Tag Manager code in your WordPress theme or Child theme. Simply edit the header.php template and paste the code right after <body> tag.

Publish Your Container

Tags in Google tag manager will not go live until you publish the container. Visit Google Tag Manager dashboard and then click on the publish button.

Publish your changes in Google Tag Manager

You can also preview your website and Google Tag Manager will show you the tags fired on each page view.

Previewing and debugging

That’s all, you have successfully installed and setup Google Tag Manager for your WordPress site. You may also want to see our guide on 7 best analytics solutions for WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

404 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • How to Fix the Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

51 Comments

Leave a Reply
  1. prakhar sahu says:
    Apr 15, 2020 at 6:41 am

    as a beginner, this post was given to me from siteground guy to help me and thanks to you as well .thankyou

    Reply
    • WPBeginner Support says:
      Apr 15, 2020 at 9:06 am

      Glad our article was able to assist :)

      Reply
  2. Jasper says:
    Jul 30, 2019 at 5:43 am

    Hi there,

    This solution works as a charm, thanks a lot. I have 1 issue though: All the way at the bottom of all my site pages there is now a white bar with the text “Javascript” written inside it on the left side of the screen.

    How can I remove that?

    Reply
    • WPBeginner Support says:
      Jul 30, 2019 at 10:11 am

      You may want to make sure you copied the entire code as that normally means javascript code you’ve added to your site may have an error.

      Reply
  3. Ann says:
    May 22, 2018 at 11:01 pm

    I’d rather not install more plugins than I need. My theme allows me to paste the GTM code with the GA tag in my header. However, how do I get the body code in my page? Do i just use a text field high up on my HOME page and paste it in there? Thanks!

    Reply
    • Nitesh S says:
      Jun 15, 2018 at 10:47 am

      Hey Ann,

      I know I’m late to reply but I’d highly recommend you install the plugin.

      Without it, you won’t be able to send detailed information to GA. I.e. If it’s an eCommerce – you won’t be able to receive product information, GTM on it’s own will give you extremely basic data and you’ll need to configure it entirely yourself which believe me takes weeks!

      Reply
  4. Naji Boutros says:
    Apr 9, 2018 at 2:08 pm

    Google Tag manager specifically says to post a portion of the code in the body of the webpage. Nothing I find on implementing Google Tag manager addresses this. Why is that?

    Reply
    • adrian says:
      Nov 11, 2018 at 1:46 am

      The video hasn’t been updated in a while. What you have to do is put the 2nd half of the code in the footer section of the plugin, which actually places it in the body section. If you look at the plugin in wordpress it says “These scripts will be printed above the tag.”

      Anything above ” is going to be in the body section.

      Reply
  5. Deelip Kushwaha says:
    Jan 7, 2018 at 12:44 pm

    Hi Admin,

    I don’t have good knowledge on WordPress.
    I am using WordPress theme for my website. And want to add google tag manager in my website. Can you please tell me how can I add tag manager code in WordPress Child theme. I am waiting for your positive response.

    Reply
  6. NM says:
    Sep 23, 2017 at 2:22 am

    Where shoud I put “Additionally, paste this code immediately after the opening tag” on Header and Footer Plugin ?

    Reply
    • JCarter says:
      Dec 4, 2017 at 2:40 pm

      Th newer version of GTM uses two codes. Place the first one in the Head and the second one just after the opening Body tag.

      Reply
      • Toni Buscarino says:
        Mar 29, 2018 at 11:35 am

        Can you recommend a plugin that lets you easily paste code after the Body tag?

        Reply
      • Naji Boutros says:
        Apr 9, 2018 at 2:09 pm

        Where in WordPress can you post a script directly after the opening body tag?

        Reply
  7. Fahad Ur Rehman Khan says:
    Apr 2, 2017 at 8:11 am

    What is the reason of using Google Tag Assistant ?

    Reply
  8. Tushar Sharma says:
    Feb 26, 2017 at 5:55 am

    Hi i want to ask when i have saved i am not able to find my code so where i can find my code

    Reply
  9. Aswani says:
    Jan 13, 2017 at 6:27 am

    Wonderful guide. I got one major confusion cleared now – whether to add google analytics code first and then add google tag manager tags. Thanks a lot for this awesome help. A big time saver.

    Reply
  10. Rob Wood says:
    Nov 21, 2016 at 5:03 am

    Hi,

    There is two elements to Google Tag Manager install

    1) in Header
    2) in Body

    Will you update your explanation to show the solution for this?

    Reply
  11. AJ says:
    Oct 9, 2016 at 12:59 pm

    Also, there’s another piece of code besides the code you mention here. They ask you to “Paste this code as high in the of the page as possible:”, and the code is:


    (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’);

    Can I install both pieces of code in the header, right next to each other?

    Thanks!

    Reply
    • Anthony says:
      Oct 11, 2016 at 3:59 pm

      Yes, Google has changed this very recently. I want this also up-to-date and by Function.php instead of a plugin. Anybody???

      Reply
  12. AJ says:
    Oct 9, 2016 at 12:51 pm

    Hi, can I have both GA and GTM in the code at the same time? Or I have to remove GA if I’m installing GTM?

    Thanks!

    Reply
    • Kevin says:
      Apr 20, 2017 at 8:57 pm

      Hi AJ,

      you can have both (GA + GTM) in the code at the same time. No worries. Although it is more convenient to fire the GA snippet also through GTM. Google provides good instructions how to do that:

      Reply
  13. Karen McElhinney says:
    Apr 18, 2016 at 7:13 am

    Is there a different procedure for WordPress.com?

    Reply
  14. Alessandro Marengo says:
    Apr 14, 2016 at 1:39 am

    Am I wrong or there is a bit of lack of support for your plugin on wordpress forum? It’s a pity… :(

    Reply
  15. Murray says:
    Mar 30, 2016 at 12:46 am

    Great tutorial – I love you guys. I read it through and then read all the comments. Got my answers. Installed it etc and then checked my site by browsing from my smartphone.
    Everything is working great!

    No questions, just a big thankyou.
    Well done :)

    Reply
  16. Gaurav Singh says:
    Mar 15, 2016 at 12:44 am

    I got This completely, But I have a confusion about there is my analytics code exist to how can I both through plugin insert header & Footer.

    Reply
    • shubhangi says:
      Nov 19, 2016 at 3:04 pm

      just place the google tag manager code below your google analytics code using plugin recommended.

      Reply
  17. Catherine says:
    Jan 25, 2016 at 7:54 pm

    I’m very new to Google Tag Manager, this is the easiest tutorial I’ve found so far without the confusion.
    However I’m wondering if there is a conflict with having both GA code and GTM code on my website?
    There is a place on my wordpress theme to insert the Google Analytics code for tracking which I have always had.
    I have now inserted the Google Tag Manager code to the header php on my site so should I remove the original Google Analytics code or does that stay?
    Many Thanks,
    Catherine

    Reply
    • WPBeginner Support says:
      Jan 26, 2016 at 5:52 pm

      You can remove tracking code from your theme.

      Reply
  18. Lisa Smith says:
    Nov 19, 2015 at 2:39 pm

    Thank you for making the plugin Multisite compatible!

    I see Google Tag Manager says to place the code immediately after the opening tag, but the plugin places it inside the tag. Will it still work if placed in the head rather than body?

    Reply
    • WPBeginner Support says:
      Nov 20, 2015 at 9:59 pm

      Yes it would.

      Reply
      • Alessandro Marengo says:
        Aug 16, 2016 at 5:31 am

        Hi!
        During the last few months I took part to several SEO courses, most of them specific on the topic GTM: since it’s strongly recommended to insert GTM right after the tag, did you plan to update your plugin in order for it to do so?
        I hope so! :)

        Reply
        • Alessandro Marengo says:
          Aug 16, 2016 at 5:32 am

          *the body tag

  19. AJ Levinson says:
    Oct 9, 2015 at 2:27 pm

    Thank you so much for this excellent tutorial.

    I am confused about a potential conflict with this method. Can you please help?

    Google Tag Manager says that the code can not be in the header. They want it right after the tag. But, if I use the Insert Headers and Footers plugin and paste the code there, won’t it put the Tag Manager code in the Header? Won’t this cause a conflict?

    In the paragraph, you wrote: “If you do not wish to install a plugin, then you can also add the Google Tag Manager code in your WordPress theme or Child theme. Simply edit the header.php template and paste the code right after tag.” Is there a step-by-step on how to do this?

    Reply
    • WPBeginner Support says:
      Oct 9, 2015 at 7:01 pm

      You can put it in the footer of insert headers and footers plugin.

      Reply
    • Jason says:
      May 31, 2016 at 4:41 pm

      You might have wondered why Google so forcefully recommends that you place the container snippet just after the opening tag. There are two good reasons to do so.

      First, if you add the tag as well (as you should), this should always be in the body of the document. The tag (which is shown for browsers without JavaScript enabled) contains an iFrame which loads the GTM library. If you add the tag into the head of your document, it can perform pretty wildly with some browsers. You could experiment with leaving the in the body, and placing the JavaScript in the , but I haven’t tested it and certainly don’t recommend it.

      The second reason is simple: to maximize data collection, the snippet should be the first thing loaded when the body of the page is rendered. Because the library is loaded asynchronously, there’s no reason to delay it at all. So have it load as the first thing when the body is rendered, so that you don’t risk losing any data due to sluggish DOM elements delaying the page load.

      Reply
      • Vince Outlaw says:
        Jun 3, 2016 at 12:55 pm

        So, if you want it to load right after the tag, then is seems like you can’t use the Insert Headers and Footers plugin because the only options are in the (nope) and right before the tag (so at the end of loading, nope).

        Am I reading this right?

        Reply
  20. steve says:
    Sep 15, 2015 at 5:55 pm

    Curious about duel installs, of both, on WordPress — I know you have to have both accounts setup in google, but does the tag manager, in effect, *replace* the GA plugin we’ve been using for a few years?

    Or, does one still install both the GA plugin AND the tag manager plugin? Seems redundant, or perhaps I’m not understanding things clearly.

    Just trying to know the most efficient way to get all the analytics I enjoy now, and all the tag manager analytics as well.

    Thanks,
    S

    Reply
    • WPBeginner Support says:
      Sep 15, 2015 at 6:03 pm

      Tag Manager is not an analytics solution in itself. It just provides an easier way to add analytics tracking in your WordPress site. If you add Google Analytics by adding it through a tag in tag manager than you can safely uninstall Google Analytics plugin on your WordPress site.

      Reply
  21. Marcelo says:
    Sep 14, 2015 at 1:03 pm

    Sorry i might be slower to understand, but what is the difference between google analytic and tag manager ? I mean, what am i missing using analytic only ?

    Reply
    • WPBeginner Support says:
      Sep 14, 2015 at 5:57 pm

      Google Tag Manager simply makes it easier to add analytics, manage and track events, and add third party scripts to your website. Tag Manager is not an alternate to analytics.

      Reply
  22. Susan Meko says:
    Sep 14, 2015 at 2:17 am

    What a detailed and step by step guide on GTM. I just completed my training on this and now I am completely clear on this.
    I believe it has nothing to do with SEO and ranking, it is just for managing all the tags we could us on our website.

    Regards
    Susan Meko

    Reply
    • WPBeginner Support says:
      Sep 14, 2015 at 6:05 pm

      Thanks, we are glad you found it helpful.

      Reply
  23. bator says:
    Sep 13, 2015 at 10:37 am

    ı couldn’t get the code. I only had save button and I saved it… =(
    ı can not see the code…

    Reply
  24. Rufus B says:
    Sep 13, 2015 at 10:02 am

    Videos please to go with the written instructions. Videos I watch, the written stuff, almost never.

    Reply
    • WPBeginner Support says:
      Sep 13, 2015 at 7:44 pm

      Please subscribe to our YouTube Channel we will try to cover this in a video tutorial soon.

      Reply
  25. Kabelo says:
    Sep 12, 2015 at 7:42 pm

    Hi, may I ask. I have two wordpress installed in one domain. eg: http://www.wp1.com/wp2.

    Will tracking wp1 be able to give me the stats of w2. If not, how may I achieve that?

    Looking forward to your response.

    Thank you in advance.

    Reply
    • WPBeginner Support says:
      Sep 13, 2015 at 8:00 pm

      You can install the same Tag in both WordPress installs. Since the tag fires Google Analytics based on domain, it will launch it on both sites.

      Reply
  26. DOK Simon says:
    Sep 10, 2015 at 5:48 pm

    That is great , simple tutorial with details. A friend told me about it but didn’t explain to this extent … Please apart from managing all script in a single dashboard does it in anyway improve the site SEO…. ??

    Reply
  27. ahmed says:
    Sep 10, 2015 at 3:12 pm

    very good thank you for sharing

    Reply
  28. Saeed Khan says:
    Sep 10, 2015 at 2:00 pm

    Brother your article is very informative. Can we used google analytics and google tag manager code together?

    Reply
    • WPBeginner Support says:
      Sep 11, 2015 at 11:50 pm

      Yes you can.

      Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
SeedProd Logo
SeedProd
Create beautiful custom landing pages - Drag & drop builder. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
Advanced Coupons
Advanced WooCommerce Coupons
Get 50% off the Advanced Coupons smart coupons plugin for WooCommerce.
WP Mail SMTP Coupon
Get $50 off WP Mail SMTP Pro so you can ensure all your WordPress emails reach the inbox.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.