Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
25 Million+
Websites using our plugins
Years of WordPress experience
WordPress tutorials
by experts

How to Install and Setup Google Tag Manager in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Are you looking to install Google Tag Manager in WordPress?

Google Tag Manager lets you add tracking code snippets to your WordPress website. It is a free tool and allows you to track different user interactions.

In this article, we will show you how to properly install and set up Google Tag Manager in WordPress and explain the benefits.

how to install and setup Google Tag Manager in WordPress

What Is Google Tag Manager?

Google Tag Manager (GTM) is a free tool by Google that lets you add, update, and manage code snippets called tags on your WordPress site.

Often website owners need to add multiple code snippets to track their conversions, form submissions, link clicks, and gather other analytical data on their website. 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, Google Ads, Google Optimize, DoubleClick, and Google AdSense. The Tag Manager also works with several third-party analytics and tracking platforms.

This saves you the time of adding and removing tags from your code rather than managing it from an easy dashboard. Not to mention, all of these separate snippets get loaded in one script.

That said, let’s see how to add Google Tag Manager to WordPress. We will also show you an alternative method for tracking different user interactions on your site. The best part, you don’t have to edit code or set up tags.

Simply click the links below to jump ahead to your preferred section:

Adding Google Tag Manager in WordPress

First, you’ll need to visit the Google Tag Manager website and click the ‘Start for free’ button to sign up.

Google Tag Manager website

After login, you will come to the add new account page.

Go ahead and click the ‘Create Account’ button.

Create account in tag manager

Next, you can enter a name for your account and select a Country from the dropdown menu.

Tag Manager will also give you the option to share data anonymously with Google. You can simply click the checkbox and scroll down.

Enter account name and country

Now, you need to add a container to your account. A container could be a website, iOS or Android apps, or a server. In this case, we will use the ‘Web’ option.

You can use your site’s domain for the container name. Once you’re done, click on the ‘Create’ button to continue.

Enter container name and select platform

You will now see a new window slide in from the right with the Google Tag Manager terms of service agreement.

You can click the checkbox at the bottom to accept the data processing terms and then click the ‘Yes’ button at the top.

Accept tag manager terms of agreement

Google Tag Manager will now create your account.

Next, it will now show you tracking codes that you need to add to your site.

Copy tag manager code

Simply copy these 2 codes, as you will need to add them to the header and body section on your WordPress website.

Adding Google Tag Manager Code to WordPress

The easiest way of adding code snippets in WordPress is using the WPCode plugin. It is the best WordPress code snippet plugin and lets you add and manage different custom codes on your website.

The best part, you can get started for free with WPCode. However, there is also a premium version that offers more features like a code snippet library, conditional logic, auto-insert snippets, and more.

First, you’ll need to install and activate the free WPCode plugin. If you need help, then please see our guide on how to install a WordPress plugin.

Upon activation, you need to visit the Code Snippets » Headers & Footers page from the WordPress admin panel. Now, enter the codes you copied earlier.

Ensure that you paste the <head> code in the Header field and the <body> code in the Body field, as you can see below.

Add header and body tag manager codes

Once you’re done, don’t forget to click the ‘Save Changes’ button.

Google Tag Manager is now ready to use on your WordPress website.

Creating a New Tag in Google Tag Manager

Next, you can create a new tag in Google Tag Manager and set up tracking on your WordPress website.

Let’s say you want to add Google Analytics 4 (GA4) to your WordPress website using Tag Manager.

First, you’ll need to click on the ‘Add a new tag’ option from your Tag Manager dashboard.

Create a new tag

After that, you can enter a name for your tag at the top.

From here, simply click on the ‘Tag configuration’ option.

Enter a title and click tag configuration

Next, Tag Manager will show you different tag types to choose from.

For instance, this will include tags for Google Analytics, Google Ads, Floodlight, and more. We’ll select ‘Google Analytics: GA4 Configuration’ for this tutorial.

Select a tag type

Next, you will need to enter the details of your tag.

First, you can add the Measurement ID.

Enter measurement ID

You can find the Measurement ID by logging into your Google Analytics account.

Simply head to the Admin » Data Streams option under the Property column. Go ahead and click on your Data Streams to view the measurement ID.

Select your data stream

When a new window opens, you should see the Measurement ID in the top right corner.

You can simply copy the ID.

Copy your Measurement ID

Now, head back to the Google Tag Manager window or tab and enter the measurement ID.

After that, you can scroll down and click on the ‘Triggering’ option.

Add a trigger

Google Tag Manager will now show built-in triggers to choose from.

Go ahead and select the ‘Initialization – All Pages’ option.

Select initialization all page trigger

After selecting the trigger, you will need to store your settings.

Simply click the ‘Save’ button in the top right corner.

Save your GA4 tag

You should now see your newly created tag.

Go ahead and click the ‘Submit’ button to run the tag.

Preview and submit your tag

Set Up Advanced Tracking Using MonsterInsights (Easy Way)

Now that you know how to install and use Google Tag Manager, you can use an easier way of setting up advanced tracking on your WordPress site.

With MonsterInsights, you don’t have to perform complicated setups in GTM. It is the best Google Analytics plugin for WordPress and automatically configures advanced tracking for you. You also don’t have to worry about making a mistake that could mess up your tracking data.

The best part, MonsterInsights shows reports inside your WordPress dashboard. You won’t have to leave your site to see its performance. It presents data that matters for your business and helps uncover insights.

For this tutorial, we will use the MonsterInsights Pro version because it includes advanced tracking features and premium addons. There is also a MonsterInsights Lite version you can use to get started for free.

First, you’ll need to install and activate the MonsterInsights plugin. If you need help, then please see our guide on how to install a WordPress plugin.

Upon activation, you will see the MonsterInsights welcome screen. You can click the ‘Launch the Wizard’ button and follow the onscreen steps to configure Google Analytics.

Launch setup wizard

For more details, please see our guide on how to install Google Analytics in WordPress.

MonsterInsights will work out of the box and automatically add tracking in Google Analytics.

Here are some of the tracking features the plugin offers:

1. Track Link and Button Clicks

MonsterInsights set up link click and button click tracking out of the box on your website. Google Analytics doesn’t track link clicks by default, and you’d have to use GTM to add tracking.

For instance, you can track affiliate performance and see which links users click the most. This way, you can grow your revenue by promoting affiliates that are getting a lot of clicks.

Outbound and affiliate links report

Similarly, the plugin also tracks outbound link clicks. These are links to other websites on your site. You can use this data to create new partnerships, sign up for an affiliate program, and create new content on your own site.

Besides that, MonsterInsights also helps track telephone links, file downloads, call-to-action (CTA) button clicks, and more.

2. Set Up eCommerce Tracking in WordPress

If you have an online store, then MonsterInsights helps you track its performance without editing the tracking script or using Google Tag Manager.

It offers an eCommerce addon that lets you enable eCommerce tracking in WordPress in just a few clicks. You can see your site’s overall conversion rate, transactions, revenue, average order value, top-selling products, and much more.

Ecommerce overview report in MonsterInsights

For more details, please see our guide on how to properly set up eCommerce tracking in WordPress.

3. Configure Form Conversions Tracking

With MonsterInsights, you can also set up form conversion tracking in Google Analytics. The plugin offers a Forms addon that automatically tracks WordPress forms on your site.

If you use Google Tag Manager, then you’d have to create separate tags for all your forms and track them in Google Analytics.

However, MonsterInsights makes this process super simple. Plus, you can view the data inside the WordPress dashboard.

Forms report

4. Automatically Enable Scroll Depth Tracking

Ever wonder how far people scroll your web page before leaving your site? Scroll depth tracking shows exactly that and helps you place your banner ads and CTAs in the right place to boost conversions.

MonsterInsights automatically enables scroll tracking on your website. There is no need for additional setup using Google Tag Manager or modifying the tracking code at all.

Scroll tracking

You can read our guide on how to add scroll depth tracking in WordPress with Google Analytics.

We hope this article helped you learn how to install and set up Google Tag Manager in WordPress. You may also want to see our guide on the ultimate guide to WordPress SEO and the best live chat software for small businesses.

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

53 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Moinuddin Waheed says

    Google tag manager aka GTM is such a powerful tool that enables tracking Google ads, Google analytics, Google optimize and Google Adsense all with the help of a snippet. This is really helpful in terms of tracking and making informed decision about different aspect of the blog and business.
    Both the methods mentioned is easy to implement and gets the GTM working for us. The second method with the plugin is better option for beginners like us. Thanks for bringing such an insightful article.

  3. prakhar sahu says

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

  4. Jasper says

    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?

    • WPBeginner Support says

      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.


  5. Ann says

    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!

    • Nitesh S says

      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!

  6. Naji Boutros says

    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?

    • adrian says

      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.

  7. Deelip Kushwaha says

    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.

  8. NM says

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

    • JCarter says

      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.

  9. Tushar Sharma says

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

  10. Aswani says

    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.

  11. Rob Wood says


    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?

  12. AJ says

    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:

    new Date().getTime(),event:’gtm.js’});var f=d.getElementsByTagName(s)[0],

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


    • Anthony says

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

  13. AJ says

    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?


    • Kevin says

      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:

  14. Alessandro Marengo says

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

  15. Murray says

    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 :)

  16. Gaurav Singh says

    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.

    • shubhangi says

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

  17. Catherine says

    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,

  18. Lisa Smith says

    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?

  19. AJ Levinson says

    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?

    • Jason says

      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.

      • Vince Outlaw says

        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?

  20. steve says

    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.


    • WPBeginner Support says

      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.


  21. Marcelo says

    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 ?

    • WPBeginner Support says

      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.


  22. Susan Meko says

    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.

    Susan Meko

  23. Rufus B says

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

  24. Kabelo says

    Hi, may I ask. I have two wordpress installed in one domain. eg:

    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.

  25. DOK Simon says

    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…. ??

  26. Saeed Khan says

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

Leave A 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.