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.

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.

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.

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.

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.

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.

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.

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
- Method 2: Install Google Analytics in WordPress with WPCode (Manual)
- Method 3: Install Google Analytics in Your WordPress Theme (Advanced)
- Bonus Tip: Track More Analytics Data in Google Analytics
- Video Tutorial: Install Google Analytics in WordPress
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.

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.

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.

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.

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.

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

Alexia
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!
Brent Sheive
Thank you so much!
JayMichaelsSDM
You just saved me tons of time …ha! So simple
g
You don’t need to pasted into the Tag, it’s better to paste into the tag right before
WPBeginner Staff
its located under the main Settings menu in WordPress admin menu.
Rebecca Hauptman Cashman
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
Jon
Awesome article! really helped me install google analytics for my blog
Nick
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.
elenaleksandra
Hi! Thanks. I use different analytics tools and they give me different reports. Who to believe?
Darshan Paladiya
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.
Rodger
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.
Ray Uotila
Paste into the header, footer or both in the plugin settings?
Giovanni
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?
Molly Fabs
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!
WPBeginner Support
Give it atleast a day.
Admin
Devesh
Hello,
I have created a blog on wordpress.com, but where will be paste code of google analytics in wordpress.com ?
WPBeginner Support
Devesh, this guide is for self hosted WordPress.org sites. Please take a look at WordPress.org vs WordPress.com guide to understand the difference.
Admin
Jim
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..
Petia Warzel
What theme is this website? BTW thanks for the article I just started my own blog.
Petja
Amber
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!
WPBeginner Support
Amber, give analytics sometime. When you first install analytics there is usually a delay in reports.
Admin
@ginabegin
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.
Darshan Paladiya
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
Becky Manuel
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
WPBeginner Support
you need to paste it immediately after <body> tag.
Admin
Sophie
Where is the tag? I can only see once space for scripts in header and another space for scripts in footer?
Darshan Paladiya
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.
Bozo Pub
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
Darshan Paladiya
Simply, you can’t do it. Google analytics data of one url can’t continue with another one.
Jerzy
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.
WPBeginner Support
Yes, you can follow the instructions provided in your theme’s documentation.
Admin
Darshan Paladiya
Still you will have to add tracking code somewhere, your theme providers won’t give it usually. They just give you copy paste interface that is easier than coding work.
Kathrine K.
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
WPBeginner Support
If it is working, then it is good.
Admin
Jenna
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!
Nishith G.
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.
Rosanne
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.
Crissy
I had the same problem. I’ve tried other plug ins and they didn’t work either.
Ronald
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.
WPBeginner Support
Wait until you upload it online.
Admin
Lucia
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!
WPBeginner Support
Lucia, you can try pasting the code using the direct paste method or use functions.php method.
Admin
Nick
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.
Norman Weathers
I’ve just started a wordpress site at quriousity.com and need to track my traffic. Your advice is invaluable.
Carlos
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
David Jonsson
do i need to put the analytics code on each blog post every time i post a blog?
WPBeginner Support
No you don’t. If you paste it correctly then it should track all your website.
Admin
E.S. Ivy
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.
Dave Jackson
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?
Hemant
Hi,
This article is really helpful, thanks for sharing. I am looking forward to read more articles in future. Keep writing!!! cheers.
Paige
I have recently switched from Blogger to WordPress and want to transfer my Google Analytics over. How do I do this?
Dan
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.
Dan
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?
E.S. Ivy
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.
Craig
How do I know if this has worked and is active?
Cheers.
WPBeginner Support
Log in to your Analytics dashboard and from the top menu click on Admin. Select the account and property you want to check and then click on Tracking Info you will be able to see a status message like Status: Receiving Data
Admin
Debbie Pugh-Jones
I have a wordpress.com site foweyholiday.co.uk. Can I use Google analytics on this as I read somewhere that you couldn’t.
thanks
WPBeginner Support
You can not use Google Analytics on a WordPress.com site. Please check out our guide on the difference between WordPress.com and WordPress.org
Emmanuel Rosani
Thank you for this awesome blog post! I’ve successfully installed Google Analytics to my new first Wordpress site..
Cheers,
Emman
zohar
thank you, this was very helpful!!
Heather
very helpful! thanks!
ahsan karim
you are great man. I have no words to thank you
Kat
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!
WPBeginner Support
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
Samantha
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
Carole Rains
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?
WPBeginner Support
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
Stephanie
If using the “Insert Header and Footer” plugin, should the Google Analytics code snippet be installed in BOTH Header and Footer or either?
Thanks
WPBeginner Support
either
Admin
paola
hi! when you add the code in the functions.php, is not missing a closing php somewhere?
WPBeginner Support
Paola, functions.php file does not have a closing php tag at the end.
Admin
Brooke Muckersie
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)?
WPBeginner Support
Brooke, yes it is right after the
<body>tag not before it.Admin
Hugh
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
vivek
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??
Shiv Saroya
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.
Ashish kausha
it is nice and very helpful for me………..
Hayley Reed
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
WPBeginner Support
By default header and footer are there on all pages in most themes and Insert Headers and Footers plugs the code into header and footer functions of WordPress.
Admin
Hugh
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