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.

zia awan
Thanks for explaining in a simple way. I add header and footer and successfully fix my Google analytics.
Abbey
Awesome video and plug in!!!!!!
Sadhan Pal
I use wordpress platform for blogging and install it. But I don’t uderstand the results of its. If I count pageviews from another counter, the result is different. Why this happen? Will you please answer me?
Thank you
Sadhan Pal
Tooba
Salam.
Thank you very much Syed Balkhi and team. wpbeginners is extremely helpful for the wp neophytes like me. Easy to follow tutotrials and one hand help. Thank you ver much for this excellent work! (Y)
Jack
Hi I see the plugin method has good feedback and is easy enough however…
“Paste the Google Analytics code in the plugin’s setting page.”
The plugin only has the option to edit or deactivate?
Rhyannon
I am having this same issue. Please advise
Amanda
I am also having the same problem. Can someone please help!?
Grace
I believe you are supposed to click on 1) “settings” then from there click on 2) “insert headers and footers” and insert the code in the footers section.
Daniel
Hmm so you recommend to put it in the footer? Google suggest to put the code in the header?!
Brianna
I have had GA installed on my wordpress for months. It has been working great, but in the last two months I’ve found that my numbers are way off. My coding looks right, so how do I fix the issue??
Nate Balcom
Hi Brianna,
What do you mean your numbers are off? Are they low? There have been some Google algo updates recently that might be affecting your results. Is this what You’re talking about?
Laura
Hi friends!
I have a question about thi topic. Where is better add my analytics code?
header.php
footer.php
functions.php
and why?
Thank you!
Nate Balcom
I would put it in footer.php. It works where ever you put it, but by including it here you insure that other page content loads before the GA script. Google Analytics is a must have, but in order to keep your page load times down you should place your javascipt references under the fold.
Kuda Makurumure
Thanks for this; very much appreciated. Used the recommended Plugins method; it’s straight forward, no issues, no fuss, works right first time
WPBeginner Support
Glad you found it helpful
Don’t forget to join us on Twitter for more WordPress tips and tutorials.
Admin
Sopani
Thanks a lot! it has been of help!
Gianfranco D AGOSTINO
Hello, i am still using my localhost/mysite as the URL of my WP site. when i am trying to register that information on the Google Analytics page, it doesn’t let me register. do i need to first put my WP on a server and register a domain name, so after that can i start using Google Analytics? Thank you very much and excuse me for my english!.
WPBeginner Support
Yes, you first need to sign up with a WordPress hosting provider. Then you will need to move your site from localhost to live server.
Admin
Missy
Please where exactly do i paste it? The header or the footer?
Joe
Footer, so it doesn’t slow down your page load.
JM Das
How to paste the code in the Insert Header and Footer Plugin. The settings page for the Plugin couldn’t be located
Sapna
Hi,
I’ve signed up and have a Google Analytics code, but am still setting up my Wordpress site and creating content; my site just has a Coming Soon page I created through a plugin. Should I wait until I launch my site to paste the Google Analytics code into Yoast/the theme’s code? Does it affect anything if I do this pre-launch?
Thanks!
Sapna
WPBeginner Support
You can add them later when you have launched your website.
Admin
Taciana
Hi,
I am using Monster Insights at my website.
Once I done all settings, I no longer need to insert Google Analytics code in every page at my website?
The plugin tracks all my pages?
It is the same ideia for Wordpress Yoast for Google Console?
Thanks!
Katherine
Hi, is there a way to tell the difference between ‘real people’ and ‘spambots’ in the analytics dashboard? I’m using the Monster Insights plugin but am pretty sure that the numbers are extremely high given I have a small local business… I’d be very surprised if the numbers I’m seeing are real people…
Hannah
Hi Katherine,
Normally you exclude ‘bots’ within the Google Analytics administrative section to be sure you aren’t getting artificially inflated reports. Go to ADMIN > VIEW > VIEW SETTINGS and check the box “Bot Filtering.” cheers-
Amy
Thank you for the tutorial – very helpful!!!
I have installed my code in a footer in the site, but I also have the Google Analytics by Monster Insights dashboard added as well – is this doubling up? I can’t really tell as I haven’t really launched the site yet, I am just in the beginning stages of getting all of the backend work completed before I truly “go live.”
Thank you again for your insights!
WPBeginner Support
If you are using Monster Insights, then you can safely remove code from your footer.
Admin
Jamie
A good tutorial, though Analytics now tracks whenever I use the WP Admin pages as well. Any idea on how to solve that?
J
To be honest, I find it unnecessary as Wordpress itself has already very good analytics and data tracking. But good tutorial.
WPBeginner Support
You are probably confusing WordPress.com with self hosted WordPress.org sites. Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.
Admin
zack
you must have skipped over the entire part about why google analytics is so important and powerful. Wordpress analytics simply don’t match up.
Andrew Carter
Extremely useful tutorial. Thank you very much indeed.
Andrew
Himanshu Sharma
Hello there
I need some help here. What to do if i had already signed up for the analytics but forgot to copy that code. How do i get the code now ?
Mariuselix
You can find the tracking code in your Google Analytics account -> Admin tab -> Property (select the site from the dropdown list) -> expand Tracking info -> click Tracking code
Fabian
top, thanks !! easy and helpful, quick & efficient ! to the point !
Anish Ponnala
Login to your analytics account.Then click on admin(it is located on the left side at the top).
Then select the website and then click on tracking info.
Philip Verghese Ariel
Hi WP team,
This is an informative tuto well explained.
How nice it would have been if I read this few years back,
I am sure this will be a great help to the newbie bloggers.
Keep sharing such informative and educational pieces.
May you have a profitable day.
Philip Ariel
Ekta
Hi, i tried to follow your instruction. I activated the plugin insert headers and footers and then went to settings.
The header and footer are blank. I just have pasted the code from Google analytics and saved. Is that correct?
I am not sure about this ”paste it in your theme’s header.php right after the tag”.
guntaka subba Reddy
How is add google analytics blog like if we are running a ecommmerce site and maintaining blog . Two different versins . please letme know
Emma C
Super helpful tutorial – thank you!
Marie
Thank you very much for this super simple tutorial! Very helpful
Tania
Very helpful! I just don’t know, after I click ‘save’, where can I see the stats. Cause I click it and nothing happens.
WPBeginner Support
You will need to login to your Google Analytics account. It may take upto 48 hours for Google Analytics to start showing stats.
Admin
Mert
Copy and paste to my theme’s header.php right after the tag will enable me to track every post and page? Or just the home page? If it is just the homepage, then how I can add this code to my every single page? Btw I do not like using plugins, since It reduces loading speed of website.
WPBeginner Support
Adding it to the head section will add the code to every page on your WordPress site.
Admin
Amber
Thanks very much! I’ve been staring at this for days >.< I'm so glad its up and running so I can see how few people I'm getting to my site ;P
pk
where we have to add this plugin…in header or in footer..
pl clarify this . it is little bit confusing.
Cameron Archibald
I would like to point out that the direct paste method states to put the code right after the tag. I would recommend putting it right before the tag. As it is Google’s recommendation and is required if you want to verify Search Console through GA method.
I think if Google recommends it you should do it right?
Cameron Archibald
Sorry the code was cut out…It states right after the body tag but it should go right BEFORE the closing head tag.
Jonathan Beltran
I believe you are correct. With the Google Tag Extension for chrome enabled, it flags that it the GA tag should be included within the tag. View this link for reference:
Jonathan Beltran
I’m sorry, it cut off. I meant that the GA script should be placed within the head tag.
Nancy
Can google analytics be added to a blog with free plan on wordpress??
WPBeginner Support
No you can’t add Google Analytics to a free WordPress.com account. Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.
Admin
Leo Stalin
Awesome explanation, thanks.
WPBeginner Support
Glad you found it helpful
Admin
Jone Quest
When I click the Add new account option nothing happen. Any ideas?
Melissa Merriam
Thanks for the refresher.
Gianni Contestabile
As usual, this was a great help! Thank you very much for the detailed info and video.
Cheers!
LIsa
Very helpful but yes, there is a bit of confusion between the written and the video ~ I added to both the header and footer box with the reasoning being that I can easily go back and edit if necessary. Thanks for all the help!
Marcus
Great help ..
Luke
What amazing explanation..
Thank you very much for your time and effort invested in this video…
Fernanda
This was great help! Thank you very much for the detailed info
Milan
The video helped a lot! It was the easiest tutorial I came across and actually worked!
Thank you so much!
Rachel
Just followed the video found it very easy to use. Thank you
WPBeginner Support
Glad you found it helpful.
Admin
Bjorn
Thanks a lot for the helpful tutorial!
Pravin Nath.K
Hey buddies, Install Google analytics using Yoast analytics plugin is best choice. If you are switch theme, the code will be on your blog forever.
Andy Simpson
Personally I’d use Google Tag Manager and then add GA
Mina
I used the plugins method. It was superb and easy as well! Thanks WPbeginner for your great tutorial.
Amy Hunt
I copied the PHP code straight into wordpress and it crashed my whole site, I had to go into my host files and delete it.
Apparently I wasn’t supposed to use the PHP at the start or end of the code along with the // at the end but why was it included??
Florence
The video shows her putting the code in the footer, but the written material says to put it in the header. Thought I would point this out. It is very confusing. The video shows script in both header and footer, but no instructions to do both.
saijad
i followed second method for adding Google Analytics in my blog.
Bud Johnson
I have installed google analytics on my computer and have also installed google analytics dashboard for wp. I have carefully gone through all of the steps in the tutorial and obtained an access code. When I paste this access code into the feed and save it I keep getting an error message. It says I don’t have a valid account. Any suggestions?
David Catlin
I initially installed “Header and Footer” instead of “Insert Headers and Footers”–very confusing! It took me a while to figure out why what I was seeing on my site didn’t quite match the video, which was frustrating. I think I have it straightened out now.