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. Great and simple post to follow! Thanks! Should be higher in Google in my opinion as it’s easy to follow with good screen shots.

    I had trouble with adding another tracking code to my new, second site. I had to log into my Google Analytics I already had and then click on the upper right “Admin” tab/button. That led me to the page to add the new site’s info. I was trying to add a whole new Google Analytics account!

    Don’t know if that will help some but wanted to share.
    Great post! Thanks for the tutorial.
    K

  2. Thanks for this information
    I have install Google Analytics on one blog, please can i use the same code for my new second blog.

    Thanks.

    • No, if you use the same code on a second blog the Analytics code will track visitors from both websites simultaneously. You will not be able to tell the difference betwee visitors from blog 1 and visitors from blog 2. You need to use a new code for each new website.

  3. Thank you for these really easy instructions. I think I’ve cracked it (took a little bit of playing around to figure out how to use the plugin). Now fingers crossed I should get the information that I’m after.

  4. In your plugin setting we’ve to insert code in footer or header or in both ?

    Please answer this ASAP. I’m stuck

  5. Hi there,

    I am trying to install my google analytics tracking code to my website via word press, and I am having a hard time getting the “insert headers and footers” plugin to install properly. I keep getting “Unable to create directory”. Anybody have any fixes to this?

    • It seems that an earlier plugin install attempt ended prematurely. Go to Plugins > Installed Plugins screen and see if you have insert headers and footers there.If it is there then try activating it. Or you can connect to your website using an FTP client and go to wp-content/plugins and delete the insert-headers-and-footers directory. Try to reinstall plugin after that.

      Admin

    • I had exactly the same problem. I overcame it by logging on to my ftp and changing the permissions, for the plugins folder on the host server, from 555 to 777 – which makes it writeable.

  6. These instructions no longer work. When I sign into my google account using your link it takes me to a Security settings page. When I just searched for Google Analyltics, there are several options. I assume “standard” is the one you recommend, but there’s no nifty walk through like you lay out in your article. After searching, I found this link to get me to where you sent us (I think)

  7. You might have already answered this but I am sick and the brain is not at 100% functioning capacity.

    1) Now that I have pasted the code into my footer via settings, does that cover very page and blog on my site?

    2) What is the benefit of pasting the code into the header as well as the footer?

    3) When I installed your plug in it warned that it may not be compatible with the latest version of wordpress 4.2.2 And I noticed that you haven’t upgraded this version in over a year. Will it still be compatible with all of the changes?

    Regards………Liesl

  8. I’m running Wordpress 4.2.2 on by blog and it says that the Insert Header and Footer plugin has not been tested on this version. Will it still work? Any other suggestions?

    Thanks.

  9. You might want to add in at the end of this article the use of the ‘Real Time’ -> ‘Overview’ report. You can immediately see if you’ve installed the tracking code correctly if you’re getting any data at all showing in GA.

    I just followed this awesome guide and was able to see myself on the site, which was pretty satisfying :)

  10. Hey, thanks this was a great help.

    At the end, after you have pasted the code, mention going back to step 4 and clicking save?

    Perhaps im being stupid, but theres no save button anywhere.

  11. Thank you for such a simple and easy video, not a tech expert and this video made it effortless.

  12. Great, thanks. I’m working on launching my new self-hosted Wordpress site. I just added the Insert Headers and Footers Plugin, like you suggested, and I pasted the code into Footers. So, we’ll see if it works! Do you happen to know if adding Stat Counter would help as well? I used to love looking at Stat Counter for my older blog, because it showed who was visiting and what they Googled to get to me. But, Google is hiding that info now, right? So, is there no point in having Stat Counter as well? Do you know of any work around trick to see that kind of info?

  13. Hi, I installed Google analytics plugin yesterday. It does not show any data from 30 days. Does it just start tracking from the day I installed it? how can I track the last years data? Thanks

    • Hi Sherluck,
      Yes, it only starts tracking once you install Google analytics. It has no historical data.

  14. Good post. Thank you.

    Near as I can determine Google Analytics will not work on a yourdomain.com wordpress.com account unless you upgrade to, or have, a Wordpress business plan. ($299/yr.)

  15. Hey,
    First I wanna say that I really love this website, been using it quite a lot lately..
    Second,
    I already have a google analytics account on a different website (actually 2), and I can’t seem to find how to add my two new sites to that account…
    I tried the help on the analytics itself, and got to the page where I can add a URL- but the fill-in boxes where grey and I had no option filling in the details. Any advice?

    Cheers!

  16. I want to ask about the analytics plugin itself. I use the one from Yoast. Is it recommended to install such plugin? Please help on this.

  17. Easy to follow and I liked the fact that you had the video as well as text to explain the how to.
    My site is set up now for tracking, thank you!

    Tony

  18. I a£ using wordpress blog from wordpress.com that doesn’t allow for plugin installation. I don’t know how to access the websites files on the wordpress.com server.

  19. I had a perfectly running report until April third. After that date my traffic is zero. Can you help?

  20. With a multisite network of independent blogs that I administer: Do I need to install Google Analytics *before* I convert the clean WP install to a multisite network, or *after* it has been networked. I want Analytics to report on each site independently.

  21. I followed all this information. but I am getting an error message as follows:

    “Tracking code on page example.com/ does not match property example sites tracking ID UA-61……”

    What might be the problem.

  22. I paste this code on my function.php bt not working so i again remove analytical code but my site still showing that “Parse error: syntax error, unexpected ‘<' in /home/eishkool/public_html/~/wp-content/themes/wpstart/functions.php on line 452"

  23. great thanks a lot, i love you guys. however google says all too briefly:

    “Create a PHP file named “analyticstracking.php” with the code above and include it on each PHP template page.”

    google provides this google tracking code to use:

    (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){

    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

    })(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

    ga(‘create’, ‘YOURTRACKINGCODEHERE’, ‘auto’);

    ga(‘send’, ‘pageview’);

    most of us will know that is the analytics tracking snippet

    so i put this in a plain txt file and save as .php fairly simple, but is this the right syntax for a php file? im new and i dont think so – but its what google said to do?. also

    including it on each php template page.. can this just be done with the php get_analyticstracking.php include tag? and if so does my analyticstracking.php script belong in my theme folder or the includes folder?

    the aim here is to call this tracking script into each template file using the include and then adding the following line to each template page immediately after the opening tag:
    to track each page where it is implemented.

    i like the idea of having the tracking done in the php rather than the open headers or footers but im not about to risk breaking the site to do this method when i dont fully understand it. am i on the right track?

  24. I see the analytics code across the top of my screen above my header even though I pasted it into my footer as instructed?

  25. Nowhere (except here, on the bottom of all the instructions) does it tell you that a Wordpress blog (not self-owned) cannot use Google Analytics! Just want a good stats tracker that will show the visitors to my (free) Wordpress blog. I have a StatsCounter counter but it doesn’t show the landing pages or exit pages. It does for my site, but it stopped doing it for my Wordpress blog a few months ago. Entirely. I took down the code and re-entered it, even signed up to another tracker and it just won’t communicate right with Wordpress and I can’t get that info! Help, anyone?

    • You are so right Lisa although it does work if in footer. The problem I’m having is when I try to verify the analytics in Webmasters Tools, it declines stating it cannot find tracking in HEAD! So I will be going back and putting in Head and not Footer.

  26. I had an Analytics account just “there,” but I didn’t use it. Now I want to start using it, and it has the correct information, but it’s showing no activities on my blog. I’ve even installed it onto my Wordpress dashboard and it’s still not showing activity.

    Any thoughts??

  27. Pasted the PHP code snippet along with my GA script in the functions.php file and it worked well. Was looking for the best way to escape using a plug-in! Thanks for this! :)

    • Thank you for notifying us, we have updated the article. This is an old article rewritten several times since then to keep up with changes. The step 6 is actually step 4 now. Hope this helps.

  28. I got a website from someone else. It already has Google Analytics installed. I assume that the Google Analytics account is connected to his Google account, so I won’t be able to transfer that to my own Google account. (It’s impossible to transfer YouTube videos from one Google account to another.)

    So if I set up my own Google Analytics account, and hook that up to the website, will I loose historical data?

    Would this procedure differ from the above?

  29. I have moved my blog from a blogspot to a wordpress and i wonder if you know if i can change the adress in google analytics to the new one?

  30. Hi,
    I am trying to set up Google Analytics with the Plugins Method (Recommended). Where do I paste the code: in the header or in the footer. Could anyone who has tried tell me whether it has worked for them?

    Many thanks
    Susana.

  31. Hi,

    I want to paste the code by using the plugin Insert and Footer. Where do I paste into the header, footer or both in the plugin settings?

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.