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.

Jason Cooper Koch
Great article! I appreciate the step-by-step approach. Just what I needed to get started with Google Analytics.
WPBeginner Support
Glad to hear you found our article helpful
Admin
kzain
this is an amazing article but what is Google Tag Manager is for? what does it do in analytics
WPBeginner Support
Google tag manager allows you to add tags to links to help you track different information based on your needs. Such as adding a tag to newsletter emails to know which email a clicked link was from.
Admin
Dennis Muthomi
I am wondering about Method 3 where Google Analytics is manually installed by adding the tracking code to the theme files.
If I update my WordPress theme in the future, will that cause the manual Google Analytics code to be removed?
I want to avoid losing all my analytics data if the theme files get overwritten.
WPBeginner Support
Yes, if you update your theme when using method 3 then you would lose your Google Analytics tracking code which is why we recommend the first two methods
Admin
Jiří Vaněk
Hi Dennis,
If you update the theme in WordPress, you won’t lose your historical analytics data. This data is stored in Google Analytics and will always be available there. However, you will lose the tracking code that you added to your theme. Therefore, it’s a good idea to use a child theme and place the tracking code there. This way, when you update the main theme, you won’t lose the tracking code because it will be stored in the child theme. It’s a simple and effective way to keep your tracking code in the theme without losing it during updates. Just remember that if you switch to a different theme, you’ll need to add the code to the new theme again. And again, the best practice is to use a child theme to insert the tracking code.
Hajjalah
I personally found the MonsterInsights plugin as the most straight-forward method to analyze website traffic with Google analytics. This is because the plugin displays all useful insights in a clear format and in a single dashboard with more deep analysis for all pages and posts traffic..
I use this plugin to track the most visited posts and pages on my website which enables me to understand the most relevant content to my visitors which has significantly increased my website traffic.
Mrteesurez
Concerning adding Google analytics to a site using Monsterinsights, if one has WordPress installed on sub directory like example.com/market, Is it sufficient to just have GA4 installed with Monsterinsights on the main site only ??
Or I will do that for each sub directory where WP is installed.
I am asking this, because I have heard main site and sub directory are considered same website.
thanks.
WPBeginner Comments
Depending on how the sites and domains are set up in this case, you would need to have MonsterInsights installed for each website.
Jiří Vaněk
I have my subdomains set up so that each subdomain has a folder in the root directory of the website on the FTP server. Since you’ll likely have a separate WordPress instance in each subdirectory, you’ll need to add the tracking code to each of these instances. The principle of tracking is that the code needs to be loaded. When it loads, it sends information about the visitor to Google’s servers. So, if you have a subdirectory with additional content, but the tracking code doesn’t load because it’s only on the main site, the subdirectory won’t be tracked, and only the main site will be measured. Hopefully, this explanation makes it clearer.
mohadese esmaeeli
Hello, friends.
I have connected Google Analytics to my site, but I don’t have options like Behavior or site speed. How can I add these settings? I would appreciate your guidance.
WPBeginner Support
For speed tests, you would want to take a look at our guide below:
https://www.wpbeginner.com/beginners-guide/how-to-properly-run-a-website-speed-test-best-tools/
Admin
Uzair
When implementing the analytics snippet through the functions.php file of a theme, there’s a risk that these modifications might be lost during theme updates. Using a child theme for such customizations is a smart strategy because changes made in a child theme won’t be affected by updates to the parent theme. This way, your analytics snippet or any other custom code remains intact and functional even when the main theme is updated.
WPBeginner Support
That is an option as well but if you are only using a child theme to add Analytics codes we would recommend using a plugin instead.
Admin
Moinuddin Waheed
Using wpcode for writing any type of additional code in wordpress is best practice.
The option of enable and disable according to our requirements has made the addition of code much easier.
It helps in managing the code snippets and check for any vulnerability that may arise due to the code.
As long as we need, enable to code snippet and disable when not needed anymore.
I think for this speicific purpose only, better to use wpcode plugin instead of going with child themes.
Fajri
Tracking a website is a must. At least you will understand how your content is doing. So you can decide what to be optimized based on the user’s behaviour.
Easiest way to do it is by using Google Site Kit plugin. But remember when you want to switch to Monsterinsight, make sure there is no double tracking code, otherwise analytic will not show the correct data.
THANKGOD JONATHAN
Thank you for the article.
I was using Blogger for my blogging and it has some inbuild analytics, so I didn’t care about using any analytics tools.
But now that I am using Wordpress I think this is very important.
Thank you once more for the helpful post.
WPBeginner Support
You’re welcome, glad our guide was helpful!
Admin
Ahmed Omar
A beginner-friendly guide on installing Google Analytics in WordPress
Your step-by-step instructions, especially the emphasis on creating a Google Analytics account, make tracking website performance accessible.
considering Google Analytics Plugin for WordPress simplifies the setup and provides additional features.
Thanks for demystifying analytics for beginners
Moinuddin Waheed
I was struggling to get my website Linked to the Google console and and Google analytics so that I can analyse my traffic on the website and work on the required path to get my website on the right track.
I am glad I found this article and connecting a WordPress site to Google analytics is infact a cakewalk. now with the help of this plugin I can easily setup my analytics dashboard and analyse my traffic sources. I can work on articles and posts best performing and get a know how of the reasons and keywords.
wpbeginner has really made the life of every WordPress newbie a go to source for any problem or question.
WPBeginner Support
Glad to hear our recommendation was helpful!
Admin
Lewis
Google Search Console added a slash at the end of my url with the prefix method. Do I add a slash to the Stream URL in Google Analytics, too?
Thanks for the great content!
WPBeginner Support
It is not required to include the trailing slash to the end of your URL, it is personal preference
Admin
A Owadud Bhuiyan
The blog is very helpful. Really, easy to read.
WPBeginner Support
Glad you think so!
Admin
Steven
Why not create a child theme and add the code to the functions file? Then you’re not depending o a plug-in and you can update your theme. (Altering themes is never a good idea, because of updates and loss of changes made)
WPBeginner Support
MonsterInsights adds markup that is normally more complex than beginner admin users are used to adding which makes tracking on the site easier. If you mean the WPCode plugin, then that plugin allows you to have the code in one place instead of searching your files for the analytics code.
Both of the methods are easier for beginners than creating a child theme. If you’re worried about the number of plugins on your site then we would recommend taking a look at our article below!
https://wpbeginner.com/opinion/how-many-wordpress-plugins-should-you-install-on-your-site/
Admin
Abid Ahmed
it’s very helpful for us thanks
WPBeginner Support
Glad our guide was helpful!
Admin
Saidsam
At all times excellent. This guide is really valuable! Thank you all.
WPBeginner Support
You’re welcome!
Admin
zainab
it isvery useful for my business.
WPBeginner Support
Glad you found our guide useful!
Admin
lusp
Hi,
I’m on step 3 and it gives an internal error at the bottom left corner, anyone knows how to solve it?
WPBeginner Support
If you mean in Google itself then you may want to try disabling any ad blockers you may be running for the most common reason.
Admin
lusp
Tried turning off ad blockers and tried it a few times in incognito mode but to no avail, the solution was to change the time zone and location to the US and it fixed the problem.
Muhammad Atif
Why you haven’t mentioned Install Header and Footer snippet Plugin to integrate Google Analytics 4??
WPBeginner Support
Insert Headers and Footers has been renamed to WPCode but it still has the same features and more
Admin
Steven Baldwin
What is the property name? for Google analytics.
Thank you
WPBeginner Support
That is a name you would set in Google Analytics so you can find it later. There is not a specific required name for it
Admin
Arnolfo Santoro
If my WordPress project starts out on a staging site, should I wait to add Google analytics until it is live?
ANGELI
Does this blog incorporate the new changes to Google Analytics? Do they impact blogs at all? Thanks
WPBeginner Support
If you mean Google Analytics v4, this article is not updated for that at the moment but we will update it as soon as the integration for it is ready
Admin
Karen
When I tried to follow these directions, I got so far, and then I got an “Authentication Issue” message. It told me I didn’t have a Google Analytics account and needed to set one up. It then directed me to this article, but this article doesn’t tell me what to do if I get the “Authentication Issue” message. It says I need to be sure I have a Google Analytics account. That’s what I was trying to set up when I got their error. Does anyone have any ideas on how I can resolve this?
WPBeginner Support
You would want to ensure you followed our step for visiting the Google Analytics site and setting up an account on their site. If you have, you may want to check that you are on the correct Google account when trying to connect Google Analytics to your site.
Admin
Jessamae Tilar
This really helped me set up my google analytics. I tried the first one and it’s so easy.
WPBeginner Support
Glad our guide was helpful
Admin
Sharon
Does the third option you listed work on the basic or standard version of WordPress? The Business version of WordPress is required to install any plugins.
WPBeginner Support
Our tutorials are for WordPress.org sites, you would need to reach out to WordPress.com for their current restrictions.
Admin
Ricardo
Hii!! I have a question… if you do this by changing the header.php on the theme.. wouldn’t it be erased when the theme updates?…
WPBeginner Support
You are correct unless you create a child theme.
Admin
Urc Ite
Hey, nice tutorial.
However, after installing the monsterInsights plugin, my website loads a bit slower.
When I run the speed test, it says “reduce render blocking”.
Is that normal??
WPBeginner Support
More than likely, the tool you are using does not like the Google Analytics tag where it is and due to Goole wanting the tag in the header it can very mildly slow a site but not enough to normally be noticeable.
Admin
Holley
I am a total non-techy newbie just starting out on a blog. I’m so glad I found you! Thank you for providing easy to understand step by step directions.
Before I found out about you, I installed a header/footer plug-in on my site based on someone’s recommendation. After watching this tutorial, is there a way to undo what I’ve done and switch to MonsterInsights plug-in? I like having it on my Dashboard and it seems easier to read (once I know what all that stuff means
WPBeginner Support
You would remove the code from the Insert Headers and Footers plugin and the code would be removed from your site and you would be able to add using the plugin method at that point
Admin
Jeff
Google Analytics does not any longer look like what you show. They have changed it.
WPBeginner Support
Thank you for letting us know about that update, we’ll look to update our article when we are able
Admin
gwendolyn
OMG… THANK YOU SOOOO MUCH. I’m starting a blog with Word Press and I have really struggled to get set up for google analytics until I found you!
You were a Blessing!!!
Thanks for your help
WPBeginner Support
Glad our guide could help
Admin
William Hails
I don’t know what I did wrong but my setup is not complete… it is not connected to my gmail account but only to my website ?
WPBeginner Support
If you have created your account then you should be able to log in with the google account you signed up with. If you have multiple Gmail accounts you may want to change accounts to see if you set up analytics on a different account.
Admin
faisal
may time i tried to install google analystics i functions.php in wordpress.
its given errors
.Your PHP code changes were rolled back due to an error on line 67 of file wp-content/themes/Extra/functions.php. Please fix and try saving again.
syntax error, unexpected ‘<', expecting end of file.
guide me what i do now.whats its solutions.
WPBeginner Support
You would want to try removing line 1 from the code in our guide for that specific error.
Admin
Tikyda
Thanks a lot for sharing on how to install Google Analytics.
WPBeginner Support
Glad our guide was helpful
Admin
Marsha
I installed Google Analytics to my blog using Monster Insights via the tutorial above but I can only see analytics using the Monster Insights dashboard on WP, the analytics is not showing up on the Google Analytics website at all.
WPBeginner Support
You would want to make sure if you have multiple properties that you’re checking the correct one and you have given 48 hours for Google Analytics to populate the data.
Admin
Elena
I keep getting this message:
“The selected account doesn’t have any Google Analytics Web properties.
Please select another Google Account and make sure your Google Analytics property is set as “Web” not “Apps and web” or “Apps”.
You can find more details about setting up your Google Analytics property in this article.
Try picking a different app/profile to auth into”
I’ve linked my account to Web only, but I don’t know if it’s an issue with how I worded the property? Please help! Thank you!
WPBeginner Support
If you have multiple properties, ensure you are connecting to the correct one, you can also reach out to MonsterInsight’s support for assistance with that error if everything is set correctly.
Admin
Lourdes
Super Helpful!!!! thanks!!
WPBeginner Support
You’re welcome
Admin
Claire
Can you set up Google Analytics for multiple websites with the same Google account? And how?
WPBeginner Support
In your Google Analytics Admin section, there is the option to add a new account that would be your new site.
Admin
David Pasquaone
Thanks! Exactly what I needed. ✌
WPBeginner Support
You’re welcome, glad our guide was helpful
Admin
putri
Thank you for the post! Your content helps me a lot in setting Google Analytics up!
WPBeginner Support
You’re welcome, glad our guide was helpful
Admin
Charlotte van Noord
after following the instructions I got this error showing up:
syntax error, unexpected ‘<', expecting end of file
WPBeginner Support
It would depend on how you are attempting to add the code, you may want to try some of the other recommended methods in the article for the moment.
Admin
Kiran
Very helpful for the beginner
WPBeginner Support
Glad you found our guide helpful
Admin
mahmoud
Thanks.
Great information
WPBeginner Support
You’re welcome, glad our guide was helpful
Admin
Thomas
Thank you for making this well thoughtout content. For FREE!
WPBeginner Support
You’re welcome, glad you’ve found our content helpful
Admin
shine htet linn
Dear Team,
I tried to connect Google analytics code to the wordpress using insert Header and Footer plugin. But when i verify it said “verification unsuccessful”. Please help me to solve it.
WPBeginner Support
You would want to start by clearing the caching on your site for the most common solution to this issue.
Admin
Srai
Excellent instructions. Thanks a bunch!
WPBeginner Support
You’re welcome, glad our guide was helpful
Admin
Stephanie
Amazing! I love how you walked through each step, was so much easier to understand, all three methods when watching you calming and in real time go through it as a newbie.
Bookmarking and Subscribing
WPBeginner Support
Glad our guide was helpful
Admin
David ayeni
thanks alot, this was really helpful, fixed it in minutes, How to i add adsense to my website after that, is there any article on that
WPBeginner Support
For adding Adsense you would want to take a look at our article below:
https://www.wpbeginner.com/beginners-guide/how-to-add-google-adsense-to-your-wordpress-site/
Admin
Chisom
Hello, Thanks for this helpful article, but i have a question,
If i use the Monster insight or the “Insert header and footer plugin”, if i create a new page after setting the analytics up, will it be automatically added to the new page or i will have to set it up again.
WPBeginner Support
Using either of those methods would automatically add the code to your new posts and pages
Admin
Ian Warner
Thanks for this helpful information. I want to install Google Analytics without Google Tag Manager. Where do I find the code for this please?
WPBeginner Support
You would not add Google Tag Manager if you do not want to use it on your site.
Admin
Dileepa K
Thanks for this detail explanation. Very helpful
WPBeginner Support
You’re welcome
Admin