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. Hi,

    Great video. What if you wanted to paste the Google Analytic code on a specific page. I wanted to paste mine on the “CART” and “CHECKOUT” pages of my website.

    Thanks in advance.

    Benjamin

  2. Hi, thanks so much for this! I have a question though.

    So I didn’t set up my wordpress site, the intern before me did. And instead of inserting the google analytics tracking code in a plugin, he inserted it in the theme header and footer.

    I foresee myself changing the theme, and just to save myself and the next intern a lot of trouble, I want to insert the google analytics tracking code through a plugin.

    There are two problems I am facing though.

    1. The universal tracking code that google analytics give me is this:

    But I spotted the tracking code in the theme footer to be an extended version that looks like this:

    So my question is, what is the difference between the two tracking codes? Does the extended version serve an additional function? If yes, what is this function?

    2. When I tried to insert the google analytics code through the plugin “Insert Header and Footer”, and then when I checked my wordpress site, my google tag assistant says that there are multiple tags detected. My question is – are multiple tags a problem? Will it affect the tracking in any way?

    Would really appreciate any help! Thank you!

  3. I wouldn’t say I’m a Wordpress beginner, but I always forget where to embed the GA Code. That and it’s changed over the years. Thanks for the post. Love the site too. Great design.

  4. When I searched for your plugin, it said it was untested with the current version of WP. Not sure if you knew that because you are so big.

    Thanks for all this information.

  5. Great and informative. However, I am not using WordPress.com Business but the premium version. I am still not able to add in the code as under setting, I dont see the install headers and footers option. How do I go about it?

  6. Hi,

    the plugin instructions say “Paste the Google Analytics code in the plugin’s setting page.” Does this mean the plugin editor? I can’t work in where to drop the code in..

    Thanks in advance,

    Meg

  7. I’ve installed your Insert ‘Header and Footer’ plugin – I was just wondering if the analytics gets put on every page on my website or just the homepage?

  8. Helpful as always!
    I do prefer plugins, but in this case I’m using google analytics on ocimpress – it’s built using WordPress but is not compatible with it’s plugins.

  9. Thanks for your excellent article. I managed to add Google Analytics to my site following your article.

  10. thanks for the clear and easy to follow steps provided on activating the code into my wordpress site it was just like A B C…….
    Keep it up i will continue subscribing to more of your products.

  11. wpbeginner has helped me configure my site to be one of the most high ranked website on google organic search results for my keywords

  12. Thank you for this article! I wasn’t sure how to implement the code to my website, after reading your article it took me 5 minuets to download and set the plugin and now my new website is all set with Analytics!

  13. I pasted the code as suggested using the plugin mentioned in the article….

    I still cannot see any stats in the reporting tab.
    Please help

  14. Worked well and very easy to do with “Insert Headers and Footers” Plugin. I added ours to the footer and it worked straightaway when I checked in the real time feature of GA. Thanks for your post.

  15. I think free wordpress.com sites can use Google Analytics if they have purchased their own domain name. Google has a Domain name provider method of verifying you own your site.

  16. Hi,
    I have pasted the google analytics code by insert header and footer plugin in header and footer. But how can I change it to before as my webpage is not crawling by search engines so for time being I have removed the code.

    Can you tell me some other way which can be work out to paste it before .
    My current theme doesn’t support in editor section. And I don’t know developer techniques.

  17. Hello,

    I have installed the Google Analytics by Yoast and it is not working! The first step in the plugin is to ‘authenticate with your google account’. When I click on that to copy and paste the code, it doesn’t seem to take it for me to continue! I have tried it many times and still nothing. Please help!

  18. Hi, I’ve entered a Google Analytics authentication code into my Yoast SEO plugin. But can you please tell me how do I access my GA dashboard for my website. And once my site is authenticated, do I still need to insert the tracking code onto all my pages. If I am using the free Yoast SEO plugin, I thought it might handle all this for me but I see no evidence of this…Do i still need to activate the ‘ insert headers and footers’ plugin? Any advice? Thanks so much for your great helpful site

  19. Hi,
    First time I visited on this website. Its looking so helpful and found knowledgeable content. Great post and useful to all bloggers. On my hostgator hosting traffic shows different and in analytic its very less comparing to hostgator. i logged in in analytic with different google id it is showing different result for each id. I think need to set up analytic..Please have a look on my website and feed back how to improve it. I am using genesis work frame + pro theme..Thanks for sharing

    • It is possible and completely normal for different analytics solutions to show different statistics. There are a variety of reasons for that, you can find more information on the topic on analytics support forum.

      Admin

  20. thanks great article
    but can i use my Gmail to manage unlimited sites
    or its 1 gmail per site

  21. i want to say thanks for your useful article!
    i use the method one and it’s work for me fine
    thanks again

  22. Thank you for this article. I have installed my google analytics code in the plug-in you suggested. I did this about 12 hours ago. So far I can not see any activity on google analytics. Is this normal or have I not installed it correctly?

    • It is normal. You can visit the Real Time section under reporting and then visit your website from some other device. You will be able to see it detected in the real time results.

      Admin

  23. Thanks for the article, I’ve installed Google Analytics on my personal blog and now I can finally check my statistics. However it displays so many data that I’m not sure if I understand everything correctly – is there any way to simplify statistics reports? Maybe some stats displayed as infographic or so?

  24. Hey

    Amazing article, learnt a lot from your blog. Thank you.
    I have a website and a wordpress blog, is it possible to link both so that i can see the same in one analytics account?

    Regards
    Deelip

  25. Hi!

    I´ve tried to seek information about plugins and Google analytics.
    If I understand correctly you must have wordpress.org ? Or is it enough to upgrade wordpress.com to premium to be able to use plugins?

    Thanks
    /Malin

  26. This was a really helpful article. But, I think there is a flaw with your plugin. It includes no way to exclude admin traffic. So Google Analytics will still show internal traffic! Yoast’s Google Analytics plugins include a way to exclude internal traffic.

  27. Hi!
    Thanks for the plug-in, really a great help for someone who doesn’t know her way around the code stuff. One question: is just pasting the code once in the header section enough to get all your pages and posts followed?
    By the way, I also follow your blog, and that’s very helpful, too! Thanks!
    Iris

  28. Hello, thanks for the write-up. Helpful indeed! I have the analytics code in and working, been so for about a month or two now. I just noticed however that my analytics code is showing up at bottom of my pages .. i have inserted in my header.php.

    I followed syntax rules I cant understand why it is showing itself .. any recommendation?

  29. Does it matter if the script is in both the header and the footer? And now that I’ve added Google Analytics to my website, where do I go to get the data? Do you have a tutorial about Analytics itself. Thanks for your help.

  30. Hi there,

    unfortunately I can’t install the above mentioned Plugin “install headers and footers” to my site. Error: The package could not be installed. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature

    Note: wpbeginners transfered my old wordpress.com site to the new wordpress.org!

    Regards,
    Amin

  31. Great article. Just one comment: you guys really fly through the videos. For those of us with no web/tech background, you should slow down the pace a bit so we can follow without constantly having to go back. Other than that, great job.

  32. Great Article..everything is clear. I have read all and I was able to install header and footer then I copy tracking code from google Analytics and then paste in myself… Save and then done

  33. Hi,

    I noticed in your video that you pasted the tracking code into the “Scripts in footer” area. This confuses me since Google’s instruction is to paste the tracking code “immediately before the closing tag” i.e, in the Header.

    Shouldn’t the tracking code be pasted into the “Scripts In Header” area then? Or perhaps it doesn’t make a difference?

    Regards
    Simon

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.