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

How to Install Google Analytics in WordPress for Beginners

You can’t improve your WordPress website if you don’t know what’s happening on it.

Google Analytics gives you those insights for free. Although it may sound technical, you don’t need to be a developer to add it to WordPress.

In this guide, we’ll show you how to install Google Analytics in WordPress step by step.

Beginner's guide to installing Google Analytics in WordPress

Before you can connect your site, you need a Google Analytics account and a Measurement ID. If you already have both, you can skip ahead to the installation methods below.

How to Sign Up With Google Analytics

To start tracking your site visitors with Google Analytics, sign up for it with your Google account.

First, visit the Google Analytics website and click the ‘Get started today’ button. Then sign in with your Google account, or create one if you don’t have it yet.

Once you are signed in, click the ‘Start measuring’ button on the welcome screen. Google will then ask for an ‘Account name’, which only appears in your own account, so enter your business name here.

Create a Google Analytics account

You can leave the data-sharing settings at their defaults and click ‘Next’.

Once your account exists, Google asks you to create a property. A property is simply the container that holds the data for one website. Enter a property name for your website, select your reporting time zone and currency, and then click the ‘Next’ button.

Create property in Google analytics

Google will then ask about your business industry, size, and goals. Answer these to match your business, click ‘Next’.

Now that your property is ready, Google needs to know where its data will come from. This is called a data stream. Since we are tracking a WordPress site, select ‘Web’ as the platform.

Select web as the data collection method

After that, enter your website URL and a stream name. By default, Google Analytics keeps ‘Enhanced measurement’ turned on, which tracks pageviews, scrolls, outbound clicks, file downloads, and more.

Next, click the ‘Create & continue’ button.

Setup web data stream

You will now see your stream details, including the Measurement ID. It starts with ‘G-‘ and is what connects your website to this Google Analytics property.

View Google Analytics tag instructions

Google also shows an alert bar at the top with instructions for adding the tracking code to your site. Click the ‘View tag instructions’ button to see them.

Switch to the ‘Install manually’ tab, and you will see the Google Analytics tracking code. You only need this code for Methods 2 and 3 below.

If you plan to use the plugin method, MonsterInsights adds the code for you.

Google Analytics code to install manually

Keep this browser tab open. You may need to come back to it while installing the code on your WordPress site.

How to Install Google Analytics in WordPress

Now that you have your Google Analytics account and Measurement ID, let’s add the tracking to your WordPress site.

There are three ways to add Google Analytics to WordPress. We recommend using a Google Analytics plugin (Method 1) because it’s the easiest and safest option for most WordPress users. You won’t need to edit your theme files, plus you can see Analytics data directly from your WordPress dashboard.

The other two methods let you add the tracking code manually. They’re useful if you prefer not to use a plugin or want more control over how the code is added.

Method 1: Install Google Analytics with an Analytics Plugin

The easiest way to add Google Analytics to WordPress is by using a Google Analytics plugin. We use and recommend the free MonsterInsights plugin. It connects your site to Google Analytics without touching any code and shows your traffic reports right inside the WordPress dashboard.

You can also find many other Analytics plugins, like Google Site Kit, which works well for basic pageview and search data. But unlike MonsterInsights, it doesn’t offer a Pro version and lacks many advanced features, like User Journey, which shows the exact conversion path a visitor took through your site.

For details, see our comparison of MonsterInsights vs. Site Kit.

First, you need to install and activate the MonsterInsights plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, MonsterInsights opens its setup wizard. If it doesn’t, go to the Insights » Settings page and click the ‘use our setup wizard’ link.

The wizard first asks which category best describes your website. Choose business website, publisher, or eCommerce, and then click the ‘Save and Continue’ button.

Next, you need to connect the plugin to your Google Analytics account. Click the ‘Connect MonsterInsights’ button.

MonsterInsights connect Google Analytics

This takes you to Google, where you choose the Google account you used to create your Analytics property. Then click ‘Allow’ so that MonsterInsights can access your Google Analytics data.

After that, select the property you created for your website from the dropdown menu and click the ‘Complete Connection’ button.

Select your Google Analytics property

MonsterInsights will now add the tracking code to your site for you. All that’s left are a few screens where the wizard suggests settings based on the website category you picked earlier.

The defaults work well for most websites, so you can click ‘Save and Continue’ on each screen.

If you see a screen asking for a license key, just click the option to finish setup without upgrading.

That’s it! You’ve now successfully set up Google Analytics on your WordPress website.

View Google Analytics Reports Inside the WordPress Dashboard

Once Google Analytics has collected some data, you can see your reports without leaving WordPress. Visit the Insights » Reports page to see an overview of your traffic, top pages, and where your visitors come from.

MonsterInsights reports in WordPress

Keep in mind that Google Analytics takes a few hours to start showing data after you install it.

Method 2: Install Google Analytics in WordPress with WPCode (Manual)

If you don’t want to use a dedicated Google Analytics plugin, then you can use the free WPCode plugin instead. WPCode keeps the code separate from your theme, so you won’t have to worry about losing it during theme updates or accidentally breaking your site while making changes.

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

Upon activation, go to the Code Snippets » Header & Footer page. Then paste the Google Analytics tracking code you copied while creating your Analytics account into the ‘Header’ box.

Paste Google Analytics code in WPCode and click Save

Don’t forget to click the ‘Save Changes’ button. Google Analytics is now installed on your site.

Method 3: Install Google Analytics in Your WordPress Theme (Advanced)

The last method skips plugins altogether and adds the tracking code directly to your theme.

Keep in mind that with this method, you will lose Analytics tracking whenever you update or switch your theme.

Simply add the following code at the bottom of your WordPress theme’s functions.php file.

add_action( 'wp_head', 'wpb_add_googleanalytics' );
function wpb_add_googleanalytics() { ?>

<!-- Paste your Google Analytics tracking code here -->

<?php }

Replace the comment line with the tracking code you copied from your Google Analytics account, and then save the file.

Your WordPress theme will now load the Google Analytics tracking code across your WordPress site.

Bonus Tip: Track More Analytics Data in Google Analytics

By default, Google Analytics tracks pageviews and basic engagement. However, it does not give you advanced reporting, like eCommerce tracking, affiliate link clicks, video tracking with Vimeo, and more.

With MonsterInsights Pro, you can enable additional tracking through addons. All you have to do is install the right addons by navigating to Insights » Addons page. Here is how to set up each one.

  • eCommerce tracking: Enable the ‘eCommerce’ addon if you run a WooCommerce store, a digital downloads store, or a membership site. You can then see which products and customers bring in your revenue, and more.
  • Set up form conversion tracking: Enable the ‘Forms’ addon to start tracking your form views, submissions, and conversion rates. MonsterInsights integrates with form plugins like WPForms, Formidable Forms, and more, so no additional configuration needed.
  • Track video analytics: Enable the ‘Media’ addon to track whether people watch your videos or click away after a few seconds. It works with YouTube, Vimeo, and self-hosted HTML5 videos.
  • Custom event tracking: With custom event tracking, you can record specific actions visitors take on your site, like a button click. It doesn’t need a separate addon to be installed.

For example, if you want to track a custom click event, then follow this formula:

<a href="https://www.example.com" data-vars-ga-category="Custom Category" data-vars-ga-action="Custom Action" data-vars-ga-label="Custom Label">Example</a>

Using this template, you’ll be able to override the default tracking behavior of MonsterInsights to customize what gets tracked as the category, action, and label. For example:

<a href="http://www.example.com/download.pdf" data-vars-ga-category="CTA">Download now</a>

To see the results, log in to your Google Analytics account and go to Reports » Engagement » Events. Your category name will appear in the list of events.

Analytics dashboard: left navigation pane and an events list; a red arrow highlights the CTA row at the bottom labeled &apos;CTA&apos;.

FAQs About Installing Google Analytics in WordPress

Here are answers to some of the most common questions we get about setting up Google Analytics.

Is Google Analytics free to use?

Yes, Google Analytics is completely free. Google offers a paid version for large enterprise websites, but the free version is more than enough for most small business sites and blogs.

How long does it take for Google Analytics to start working?

After you add the tracking code, Google Analytics may take a few hours to begin showing data in your reports. We recommend checking back after 24 hours to see your first full day of statistics.

Do I need Google Analytics if my site has Jetpack Stats?

Jetpack Stats gives you a simple overview of your traffic. Google Analytics goes much deeper, with detail about your audience, their behavior, and how they found your site.

For a full comparison, see our article on Google Analytics vs. Jetpack Stats.

How do I keep personally identifiable information (PII) out of Google Analytics?

Google’s terms do not allow you to send personal details like names, email addresses, or phone numbers to Google Analytics. To ensure you’re not accidentally adding such details via forms, you can go to Admin » Data streams and select your website’s stream in your Google Analytics Account. Then click ‘Redact data’ and strip any URL parameters.

If you use MonsterInsights, the Privacy Guard feature does this automatically from Insights » Settings » Engagement. It is included in the Plus plan and higher.

Video Tutorial: Install Google Analytics in WordPress

If you prefer to watch the process, our video tutorial shows you how to install Google Analytics in WordPress.

Subscribe to WPBeginner

We hope this article helped you learn how to install Google Analytics in WordPress.

Next, you may want to see our ultimate guide to GA4 in WordPress to make sense of your new reports. You can also check our WordPress SEO guide for tips on growing your traffic in AI search era.

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.

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

853 CommentsLeave a Reply

  1. I’m trying to install the GCE on my Wordpress site, and I’ve got the code installed in the of the theme header.php. The code validates for both pages on Google Analytics. But when I try to then load my “original” page on my site, I get a 404 error. I’ve been researching and it seems like it is something to do with the server security, but my contact at our host is having trouble determining how to address this. Do you have any specific suggestions for what server files / permissions needs to be modified to get this to work? Thanks!

  2. I installed the plugin, and the next step is to go to the settings area, however this plugin doesn’t have a settings area. There is the option of “deactivate” and “edit” but other plugins have the “settings”, “deactivate” and “edit” links… this one doesn’t. What do I do now?

    Thanks

  3. Thanks for the article. It helped with a few issues I’ve been having. First and foremost of course was not having the code in my site. I was able to get it working with both functions.php and the recommended header/footer plugin.

  4. Hi! Thanks. I use different analytics tools and they give me different reports. Who to believe?

    • I think you should trust Google. That is because apart from directly added tracking code, no other company can has as much data about your website as Google has.

      And apart from that, most of the organic traffic from any website is mostly from Google. So original Google analytics data can be more useful in creating a solid strategy that impacts your Google results compared to any other service.

      That’s how I think, I am not an expert but surely an SEO with 18 months of experience. Anyway good luck with your site.

  5. Regarding Insert Headers and Footers method, Would be worthwhile to advise on pasting the script in the Insert Header or Insert Footer space – These scripts will be printed in the section. OR These scripts will be printed above the tag.

  6. I pasted my Google Analytics code using Insert Headers and Footers, but the status of my tracking ID is still showing not installed. How long does this take to show it has been installed or did I do anything wrong?

  7. I’ve added my tracking code to the header.php file of my theme (suits), by manually pasting it in. I’ve tried it right after the body tag, as you suggest, and also right before the close of the head tag, which I’ve seen advised elsewhere. (not pasting the code twice, just trying it in each location by itself). In both instances, my Analytics account says: tracking not installed. Any idea why GA isn’t seeing my code? Thanks in advance!

  8. Hello,
    I have created a blog on wordpress.com, but where will be paste code of google analytics in wordpress.com ?

  9. Hi,

    I inadvertently have the Google Analytics script in my home page twice. Once put in by someone helping and another by a plug-in.

    I’ve been able to view/modify the HTML in the past, I think, I but can’t for the life of me find where to access the full HTML.

    I can see visual vs text but don’t believe that gives me enough of the HTML to modify/remove one of the Analytics scripts.

    I’ve also looked at Appearance>Editor but that seems to be about themes..

    I can see what I want to remove if I go to a “view source” page looking at my page from a web browser.. but can’t find it to remove it through WP.

    Any help would be appreciated.
    thanks
    Jim H
    PS I am using a Genesis theme News Pro and Premise..

  10. Thank you for this! I have a question. Google analytics has me at 3 visitors and then 0 visitors where wordpress has me at 30 and 50 for those days. I did just start my blog. Why would GA not be picking it up? Thanks!

    • How are you seeing analytics from Wordpress itself? I thought this was just available on Wordpress.com sites, not .org, and that Google Analytics was only available for .org.

      • Hey @ginabegin:disqus, I think you should try installing plugin, either “Jetpack” or “Google Analytics Dashboard for WP”.
        Both of them make site analytic available in Wordpress.org

  11. Hi,
    I’m ready to paste my code, and you said do it after the body tag, but I’m not sure exactly where you mean. As in, hit return after I see the words <body >
    then paste?
    Or paste at the bottom of that whole block (which would be the end of the page) as the last item on the whole page?
    Please help thank you

      • Where is the tag? I can only see once space for scripts in header and another space for scripts in footer?

        • Sophie, don’t mind it. Usually you will see only blank space for scripts. Still it works. The case depicted by Becky is exception.

          Just give your Analytics some time after installing script in those fields.

  12. Hello,

    thanks for the informative article. I’m interested in following:

    I had a website in Joomla, with already inserted analytics code. Now, I have created a blog in WP, with the same name, but with changed adress (now it have /blog in the extension).
    What is the procedure to keep running the existing code because I want to keep running my statistics record from previous site.

    Thanks

    • Simply, you can’t do it. Google analytics data of one url can’t continue with another one.

  13. Hi,

    If the WP theme I’m using as a Google Analytics configuration already built in, I am correct in assuming that I don’t need to follow the 3 steps of pasting code in your tut above?

    Thank you.

  14. Hi!

    Thanks for a wonderful guide!
    I was wondering what happens if I have my code in the header.php right before the ? I read another guide before yours, stating that this was where to put it.. That’s where it is now and my analytics seem to work?

    Best,
    Kathrine

  15. I installed the plugin but there was no settings page. Is there a certain area in the code that I paste the script?

    Thank you!

  16. I started it 1 hour ago and finished it now. Thanks to this beautifully crafted article that helped a newbie like me to finalize each and everything so smoothly.

    Waiting for the data to populate in GA dashboard now.

    God bless you Syed.

  17. Hi, I downloaded the plug in and followed the directions listed, but on GA it still says that it’s not installed…I’ve given it 12 hours…Any trouble shooting ideas? I chose to paste the script into the footer and made sure I hit save after I copied over the script.

  18. I have just started building a new site on WordPress and am building it on my computer as a local host first before I transfer it over to an online host. What I want to know is can/should I activate the Google Analytics plugin now or wait until I have uploaded it to a online host.

  19. Thank you so much for these clear and detailed instructions. I did everything you said and it worked out great up until pasting the code into the header and footer plugin. Because after I do that, the code is actually visible in the header of my website. What am I doing wrong?

    Thanks for your support!

    • You may also be posting code which is missing the tag. This will cause PHP to read it as regular HTML depending on the particular situation and very likely could be the reason you’re seeing plain text at the top of your site after posting a script in to the header.

  20. I’ve just started a wordpress site at quriousity.com and need to track my traffic. Your advice is invaluable.

  21. Hello,

    Thanks for the informative article.

    I followed the instructions for CapitalHustle.com however the Google Analytics still shows “Tracking Not Installed.”

    I pasted the code into the header and footer sections of the plugin settings. Am I missing something?

    Thanks!

    Carlos

  22. The headers and footers plug-in is really nice so that I don’t have to worry about messing up the rest of the code!

    I was wondering, am I right that this also means that a Wordpress upgrade won’t make these changes disappear? I keep putting of learning how to make a child theme. :) And I think this was the one change I had made to my code previously. I forgot about it and then it disappeared with a Wordpress update.

  23. on a site I manage, I have installed google analytics but despite having visited the site using my phone so it is from a different ip address from where I am managing it, it still shows up as there being no traffic. How long after installing do I have to wait before I start seeing results?

  24. Hi,

    This article is really helpful, thanks for sharing. I am looking forward to read more articles in future. Keep writing!!! cheers.

  25. I have recently switched from Blogger to WordPress and want to transfer my Google Analytics over. How do I do this?

  26. I used the plug-in method to install google analytics, but it keeps saying that tracking is not installed. I copied the tracking code from google and pasted it directly into the settings for the plugin insert header and footer. Any suggestions for what I can do to fix it or any idea why it is not working? My website is http://www.thesimplestform.com/
    The tracking code shows up when you do view source.

  27. I used the plug-in method to install google analytics, but it keeps saying that tracking is not installed. I copied the tracking code from google and pasted it directly into the settings for the plugin insert header and footer. Any suggestions for what I can do to fix it or any idea why it is not working?

    • I was having this problem too. Not sure if it was just time, but I also have W3 Total Cache installed and it might have helped to empty the page cache.

  28. Thank you for this awesome blog post! I’ve successfully installed Google Analytics to my new first Wordpress site..

    Cheers,
    Emman

  29. I have Google Analytics installed on my web site, and i’ve just created a folder area to house our new blog. Do I need a separate tracking code to track the blog statistics, or just install same site-wide tracking code through the header/footer plug-in? If so, where in Google Analytics would I view the blog stats specifically? Thanks for your help!

    • if your new blog is actually a separate website on its own, then you better create a new project in Google Analytics. If it is under the same website but in a subdirectory then you can use the same analytics code.

      Admin

  30. Thank you, this was very helpful. I was really confused about how to get that code into “every page on my website” without going though a bunch of work, but that “insert header and footer” plugin is a really fast and easy way to do it! Thanks again,

    -Samantha

  31. I have been using Google Analytics for about 6 months, but want to utilize the Demographics and Interests data. I keep getting a message that I need to implement a code change to allow that data to be accessed, but I’m not sure how or where to make this code change. Can you provide some guidelines please?

    • Carole when you first integrated Google Analytics in your website you would have inserted a piece of code somewhere on your site. Now you need to update that code and replace it with the new one.

      Admin

  32. If using the “Insert Header and Footer” plugin, should the Google Analytics code snippet be installed in BOTH Header and Footer or either?
    Thanks

  33. Hi there, just one thing… is this an error in your post?

    “Direct Paste Method
    Copy the code that you received in Step 6, and paste it in your theme’s header.php right after the tag.”

    Shouldnt that be ‘before the tag.’ (not after)?

      • Doesn’t Google Analytics make asynchronous calls? I guess that’s why instructions say “Paste your snippet (unaltered, in it’s entirety) into every web page you want to track. Paste it immediately before the closing tag.”

        Yoast’s plugin Google Analytics for WordPress also loads the tracking code in the header

  34. I used the plugin you recommended and i doubt that is it important to paste the whole Google Analytics code in both header and footer boxes?? or header is enough??

  35. As we all know Google Analytics has changed it dashboard like anything. day by day it becomes more user friendly. Nice post. Keep sharing like this.

  36. Hi there
    I am using the header and footer plugin for GA in my wp blog and was wondering if there was any way to exclude pages such as the legal pages etc

    thanks

    • You could try using filters (Admin > Views > Filters). A custom filter excluding the page title field may work

      Another option is including the GA code conditionally, of course, in this case you can not use a plugin

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.