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. Please I am having issues registering my blog to the google analytics. I keep being told that my blog URL is not allowed.

  2. Hey, i have installed monster insights. When i open it shows “You appear to be offline” I can’t see any stats or other things. Why? I can see stats by going to Google analytics website.

    • It sounds like when you opened the page with MonsterInsights you had an internet issue. You would want to clear your cache and that should resolve the issue.

      Admin

  3. Hi, I am using a personal plan so I can’t install any plugins.

    I have gone to my dashboard to try and install the code manually, so I scrolled to appearance but I don’t have an editor option.

    Does this mean I have to upgrade to business plan? Because that would be too costly for me.

  4. i have added my google analytic code to.my wordpress site ,so then also i am not getting traffic to my website,what will be the readon for the same

  5. Thank you for the information. I am currently using the first option but I recently got a message that says: No Hits

    Property is not receiving hits.

    I am no longer getting a page view analysis or any info.
    What can I do to resolve it?

    • Have you tested with an incognito browser to see if it counts a hit? The MonsterInsights plugin would normally filter out admin activity

      Admin

  6. I have blog on wordpress.com with premium (8 dollars a month) subscription and I can’t implement code from Google Analitycs. Is there any script for that or I must upgrade for bussienes plan or maybe migrate on wordpress.org

  7. Hi there! Thank you for yet another amazing article. So I had installed GA via Monster Insights a couple of years ago but I also have the Headers & Footers plugin for other uses anyway. I am currently looking into getting rid of some plugins so I want to ditch the Monster Insights one as I never look at the metrics from WP anyway. What should I do? Add the GA tracking code to header first and then delete Monster Insights plugin or vice versa? Will this change affect my stats somehow? Will I lose any stats in the process? Thank you so much in advance.

    • You would want to add your code after removing MonsterInsights, you shouldn’t lose any data you would only lose any specific setup that you had in MonsterInsights such as filtering out your visits.

      Admin

  8. Amazing tutorial, thank you for taking the time to record and show all 3 methods. I have watched so many video’s that simply say, now add the code to your website, and then move on to the next topic. Have been looking for ages to find a video that shows you how to add the code.
    Thanks to Jaison from bluehost help for connecting me with this video!

    • It would depend on the issue you’re running into, if there is an error, reach out to MonsterInsight’s support and they will be able to assist

      Admin

  9. Well, unfortunately this plugin crashed my website and WP is asking for $185 to fix it. I cannot access my website to uninstall Google Analytics. Any suggestions? I am a true Beginner to all of this.

  10. Hi. In section 3 where you say to add the code immediately after the tag, shouldn’t that be immediately after the opening tag?

    • We recommend the location we do in the article as your site would load the scripts above it first to start displaying your site before loading Google Analytics rather than first waiting for Google Analytics tracking then displaying your content.

      Admin

  11. Hi, yesterday I installed using Monster Insights and kept scrolling to read, then closed down for the evening. Today, I opened it back up, forgot that I’d already installed MI and used the header/footer method. Will they cancel each other out, or is it okay to leave it?

    Thanks,
    Becky

    • You would want to remove the header method and keep the MonsterInsights method if you want to keep using MonsterInsights. If you don’t remove the extra method then it would show incorrect information.

      Admin

  12. Thanks so helpful, and so easy to follow. I stuck with your header and footer plugin as analytics stop communicating with another plugin that I was using.

  13. The insert header and footer plugin helped me a lot. I use Flatsome child plugin and dont know how it works with that system…

    with the plugin it was easy going :)

    Thanks a lot!
    Cheers,
    Patrick

  14. Hi,
    Thanks for this article, it’s very clear and easy to follow. I have successfully installed monsterInsights and have been tracking for a few days now.

    However Analytics seems to track only normal pages and not post-type pages (posts, news, etc.) on my site. Any ideas how to fix this? Thanks!

    • If it’s not tracking your analytics correctly for your posts, if you reach out to MonsterInsights’ support they should be able to help you check for any errors with the plugin.

      Admin

  15. Your PHP code changes were rolled back due to an error on line 534 of file wp-content/themes/infinite/functions.php. Please fix and try saving again.

    syntax error, unexpected ‘<'

    That's the message I get :-/

    • It would depend on the method you were using to place the code for why that error is popping up. If you’re using the manual method you may want to try adding to your functions.php

      Admin

  16. Can I use Google Analytics with a Premium subscription in WP?
    I’ve this doubt ’cause on the official subscription page they say that the Premium account doesn’t support Google Analytics.

    • If you’re on WordPress.com then they normally require the business plan, our tutorials are for WordPress.org sites :)

      Admin

    • You would either use inspect element to see if your code was added to your site or you could wait the 14-48 hours to see if it starts collecting your site information.

      Admin

  17. When I try to set up google analytics it says my URL is invalid. I have checked it and triple- triple checked it. I’m not sure what im doing wrong.
    any suggestions?

    • You may want to check that if your site is using https the url you have set in Google Analytics is also the same.

      Admin

  18. Hello, I have a free wordpress.com account and to use the MonsterInsights or headers/footers plugins, it is requiring me to upgrade to a premium business account. Is there a way to use Google Analytics without paying for a business account?

    Thank you in advance.

  19. Hi, I have tried following the steps in your tutorial, but when I try to connect to google analytics, I am constantly told that I google analytics is only available with a “g suite” email, not an email ending in gmail.com. But I see in your example where it says “allow monster insights to access your google account” that your sample email ends in gmail.com. How can I get past this to access google analytics for my site? Thanks.

    • You would want to ensure you are using the same email you used to create your Google Analytics account and if you continue to have that problem, if you reach out to the plugin’s support they should be able to assist.

      Admin

  20. Is it okay to have the Yoast SEO plug in AND monster Insights, or should I get rid of the plug in? (I was finding it difficult anyways and don’t think I have it set up properly)

    • You can use both plugins, MonsterInsights helps you see what Google Analytics is saying about your site while Yoast helps Google understand what your site is about :)

      Admin

  21. Is it OK to add the UA-XXXXXXXX code to BOTH the “Monster Insights” plugin – AND TO – the “All in One SEO ” plugin at the same time ?

  22. I am very much confused how to add google analytics to my site. If i donot want to use the pluggin which steps I should take?

  23. Very good post. As a newbee in this field, I was able to install the Insert Headers and Footers Plugin and connect with Google Analytics. This was for my Photography website.
    Besides this, I also have a business website where I want to install this plugin and have Google Analytics. How can I do this? When I signin with Google, I am always redirect to Google Analytics of my Photography website?
    How can I have a new script for my business website?
    I hope to get a clear answer as I’m a newbee :-)

    • Hi Eric,

      Google Analytics allows you to add multiple websites. It calls them properties. Under your Google Analytics account click on the “Admin” menu at the bottom left corner of the screen. After that you will see an option to Add Property.

      Admin

  24. I’m so grateful for this article! I have been banging my head trying to figure this out on my own. Thank you!

  25. Hi, I already had the Headers and footers plugin, since I have installed Monstterinsights, can I now uninstall Headers and Footers? Thanks.

  26. Being a newbie at blogging, I see now that when I first set up my blog I used the Insert Headers and Footers for my Analytics code. A year later (not knowing what I was doing) managed to set up MonsterInsights with a new Google Analytics account. I have now realized that I have two Google Analytics accounts tracking the same blog- one through Insert Headers and Footers and the other through MonsterInsights. Interesting to note, Insert headers and footers shows more visitors a month (almost 5,000 more). Which one do you think is more accurate? Which one do you think I should keep? Are there any negatives if I stop using one of them? Thanks so much for this video and advice!

  27. I can NOT seem to access the functions.php folder ANYWHERE!!! :( For whatever reason when I click on “Appearance” in the sidebar all I see is “Themes, customize, widgets, menus, header, background, theme options, amp, and Mobile” Where is Editor?? What is going on??

    • Hi Tyler,

      functions.php is a file not a folder. You can also access it using FTP, simply connect to your website and go to wp-content/themes/your-theme-folder/ inside you will see your theme’s functions.php file which you can then edit using a plain text editor like notepad.

      Admin

  28. Well, i thought you were kidding. Many Tutorials make it so complicated and you got it done in 3 minutes!
    Thank you so much for that!

  29. which one is best plugin one or directly adding code to header…which one make page slow or website slow as compare to other

  30. Hi,

    I was using last method previously. I recently upadated theme. I was adding code in header.php and was adding code below tag. Because now I am unable to track and also unable to see code in view source Does mosterinsights show on analytics.google.com.

    Am I correct.

  31. I don’t know what’s wrong but my Analytics only detects AMP view so I tried to add new GA account and followed all these steps. Hope my stats back to normal. Thank you.

  32. Hi…
    Is it posaible to add two websites to a single google analytic account?
    If yes, how can I do that?

    • Hi Gabriel,

      Yes, you can add multiple websites to Google Analytics using the same Google account. Simply go to Google Analytics dashboard and click on the ‘Admin’ button. On the next screen, you can click on ‘Create New Account’ button and add another website.

      Admin

  33. Hi guys!

    Long time fan and customer (Love my WPForms!).

    Question regarding this great post:

    Are there any negative effects if I add BOTH plugins?

    Thanks for your great work,

    Speaker Tim White

    • Hello Tim,

      Yes, there are negative effects if you used both plugins. They will both be loading Google Analytics which would affect reporting. We recommend using MonsterInsights, because it will give you access to beautiful reports and advanced features.

      Admin

  34. Great description! I’m a WordPress-beginner and found it incredibly useful. I set it up in just a few minutes thanks to your detailed step-by-step-instructions! :)

  35. Hey dude,

    This is really complete. However, I rather to know that is it better to install GA later when a new site reaches a certain decent traffic

    thank you

    • I’m not sure I agree with this. I don’t think it’s ever too early to setup GA. in fact it’s one of the first things I setup. Almost no fun if you can’t see what kind of traction your blog is getting.

  36. when i’m clicking on monsterinsight install. nthng is happening and install button is not accessible to me.

  37. Simply edit the header.php file in your WordPress theme and paste the code you copied in step 4 right after the tag.

    Is it really true ” right after the tag.” ?

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.