Do you want to install Google Analytics in WordPress? Knowing how your audience interacts with your website is crucial for your success.
The best way to know your audience is through your traffic stats, and this is what Google Analytics provides for FREE.
In this article, we will share why Google Analytics is important, and how you can easily install Google Analytics in your WordPress website (step by step).
First, we will explain why Google Analytics is important and how it can help you grow your website.
After that, we will show you how to sign up for a Google Analytics account and different methods to install it on your WordPress site.
Finally, we will explain how to view your traffic reports in Google Analytics.
Here is a quick overview of what you’ll learn in this article.
- Why is Google Analytics Important
- How to Sign up with Google Analytics
- How to Install Google Analytics Using MonsterInsights (Recommended)
- How to Install Google Analytics Using Insert Headers & Footers Plugin
- How to Install Google Analytics in WordPress Theme (Advanced)
- Viewing Reports in Google Analytics
- Making the Most out of Google Analytics
Ready let’s get started.
Video Tutorial
If you don’t want to watch the video tutorial, then you can continue reading the text version below:
Why is Google Analytics Important for Bloggers?
Once you start a blog, your #1 goal is to get more traffic and subscribers. Google Analytics help you make data-driven decisions by showing you the stats that matter. You can see:
Who visits your website?
This part of analytics answers what is the geographical location of your audience, which browser did the user use to visit your site and other important information such as screen resolution, JavaScript support, Flash support, language and more.
This data is extremely useful, and it can help in numerous ways. When getting a custom design, you can use the user data to make sure that your site will be compatible with your audience.
If most of your users don’t have Flash support, then you should avoid adding the flash element in your site. If most of your users are on 1280 screen resolutions, then make sure that your design is compatible with that resolution or smaller.
What do people do when they are on your website?
You can track where the users are going on your website, how long do they stay on your website, and what is the bounce rate (the percent of users exit your site on the first visit).
By using this information, you can decrease the bounce rate and increase your pageviews.
You can also find your most popular articles, articles that are not doing so well, and what kind of content your users are looking for.
When do people visit your website?
By looking at the hottest hours in the day for your site, you can pick the time when you publish your post. If that time zone is not compatible with yours, then you can schedule your post to meet that hour.
How do people find your website?
This section of the analytics shows you where did the users come from (for example: Search Engines, Direct Links, Referral links from another site).
It also shows you what percentage of your visitors came from each of these sources. Google analytics gives you the breakdown of each of these categories. If it is the search engine category, then it shows you which search engine got you the most traffic, Google, Yahoo, Bing etc.
The breakdown of referral sources shows you which sites you need to work with the most. If your top referral source is Facebook, then you need to have exclusive Facebook content to make your Facebook audience feel special.
If your top referral source is an external website, then you might want to consider having a partnership with that website (guest post exchange or something else).
How do people interact with your content?
Google analytics shows how your users interact with your site’s content. It shows you what percent of the user clicked on which link on your site and much more.
You can run A/B split tests by creating content experiments in Google Analytics to understand what works best to meet your goals.
By seeing the user interactivity, you can work your content around your users. By seeing the answers to the questions above, you can focus on the strategies that work for your site and avoid strategies that don’t work.
Simply put, eliminate the guesswork and focus on stats that matter, so you can make data driven-decisions.
How to Signup with Google Analytics
Google Analytics is available for free and all you need is a Google or Gmail account to sign up. The sign up process is quite simple, follow the step by step instructions below to create your Google Analytics account.
Step 1: First you need to visit Google Analytics sign up.
You will be asked to login with your Google account. If you already have a Google or Gmail account, then you can use that to sign-in. Otherwise, you can go ahead and create a Google account for yourself.
Step 2: Once you sign-in with your Gmail account, you will be prompted to a screen like the one below. This is where you will signup for Google analytics with your Gmail account.
After that, you will be asked to provide an account name. This name will be used internally so you can use anything like your business name.
Step 3: On the next screen, you will be given choice to choose between a web, apps, or apps and web. Make sure you select ‘Web’.
After that, you need to enter website name, website’s URL, country, and time zone.
Once you have entered this information, click on the Next button. You will be presented with Google Analytics terms and service which you must agree to, so click on ‘I Agree’ button.
Step 4: Now you will be presented with your Google Analytics tracking code. You can copy this tracking code because you will need to enter it in your WordPress site depending on the method you use below.
You cann also simply leave this browser tab open and switch back to copy the code when needed.
We suggest leaving the analytics browser tab open as you may need to revisit it, once you have installed the code on your WordPress site.
Now that you have setup a Google Analytics account, let’s take a look at how to install Google Analytics in WordPress.
How to Install Google Analytics in WordPress
There are a few different ways to setup Google Analytics in WordPress. We will show you three methods where the first option is the easiest and the last being the hardest.
You can choose the one that best suits your needs.
Note: You need to use only one of these methods on your website to avoid double tracking of page views in your Google Analytics account.
Method 1. Google Analytics for WordPress by MonsterInsights
MonsterInsights is the most popular Google Analytics plugin for WordPress. Over 1 million websites use it including the likes of Bloomberg, PlayStation, Zillow, and more.
It is the easiest and by far the best way to add Google Analytics to WordPress (for all users beginners and experts alike).
MonsterInsights is available as both, a paid premium plugin, and a free version. In this tutorial, we will be using the MonsterInsights free version.
You can use the MonsterInsights Pro version if you want more advanced features like E-commerce tracking, Ads tracking, Author tracking, etc. The process of setting them up is the same.
Let’s get started.
The first thing you need to do is install and activate the MonsterInsights plugin. For more details, see our step by step guide on how to install a WordPress plugin.
Upon activation, the plugin will add a new menu item labeled ‘Insights’ to your WordPress admin menu. Clicking on it will bring the MonsterInsights setup wizard.
First, you will be asked to choose a category for your website (a business website, blog, or online store). Select one and then click on ‘Save and Continue’ button.
Next, you need to click on the ‘Connect MonsterInsights’ button.
This will bring up a popup that will take you Google accounts where you will be asked to sign in or select a Google account if you are already signed in.
Next, you will be asked to allow MonsterInsights to access your Google Analytics account.
Click on the ‘Allow’ button to continue.
The final step is to select the profile you want to track. You need to select your website here and then click on the ‘Complete Connection’ button to continue.
MonsterInsights will now install Google Analytics on your website. After that, you will be asked to select the recommended settings for your website.
The default settings would work for most websites. If you use an affiliate link plugin, then you need to add the path you use to cloak affiliate links. This will allow you to track your affiliate links in Google Analytics.
Click on the Save and Continue button to save your settings.
Next, MonsterInsights will show you paid add-ons that you can access if you upgrade to PRO. You can simply click on the ‘Save and Continue’ button to skip this step.
After that, you will be asked to install WPForms plugin, which is the best WordPress contact form plugin. You can install it or simply click on ‘Skip this Step’
That’s all you have successfully installed and setup Google Analytics on your WordPress site. Remember, it will take Google Analytics sometime before showing your stats.
The best part about MonsterInsights is that you can view your Google Analytics reports inside your WordPress dashboard. Simply visit Insights » Reports page to check out a quick overview of your analytics data.
Note: MonsterInsights was formerly known as Google Analytics for WordPress by Yoast. WPBeginner’s founder, Syed Balkhi, acquired the plugin in 2016 and rebranded it to MonsterInsights. Now it is part of our family of premium WordPress plugins.
Method 2. Insert Headers and Footers Plugin
This method is not as good as MonsterInsights because you will not be able to do advanced tracking configuration, and you will not be able to view Google Analytics data in your WordPress dashboard.
First, you will need to copy your Google Analytics tracking code that you copied earlier in Step 4 when signing up for Google Analytics account.
Next, you need to install and activate the Insert Headers and Footers plugin. For more details, see our step by step guide on how to install a WordPress plugin.
Upon activation, you need to visit Settings » Insert Headers and Footers page. Here you need to paste the Google Analytics tracking code that you copied earlier into the ‘Scripts in headers’ section.
Don’t forget to click on the save changes button to store your settings.
That’s all, you have successfully installed Google Analytics on your site.
3. Install Google Analytics in WordPress Theme
This method is for advanced users who are familiar with the code. It is somewhat unreliable because your code will disappear if you switch or update the theme. We almost never recommend using this method.
If this is your first time adding code to your WordPress files, then you should check out our guide on how to copy paste code snippets in WordPress.
First, you will need to copy your Google Analytics tracking code that you copied earlier in Step 4 when signing up for Google Analytics account.
Now there are two common ways to add this code in your WordPress theme files. You can choose either one of them (not both).
1. Add code in header.php file
Simply edit the header.php file in your WordPress theme and paste the Google Analytics tracking that code you copied earlier right after the <body>
tag.
Don’t forget to save your changes and upload the file back to your server.
Add via Functions File
You can also add Google Analytics tracking code to WordPress functions file. It will then automatically add the tracking code to every page on your WordPress site.
You will need to add this code to your theme’s functions.php file.
<?php add_action('wp_head', 'wpb_add_googleanalytics'); function wpb_add_googleanalytics() { ?> // Paste your Google Analytics tracking code from Step 4 here <?php } ?>
Viewing Reports on Google Analytics Website
Google Analytics is capable of showing you a treasure of data collected from your stats. You can view this data by visiting your Google Analytics dashboard.
You will see the built-in Google Analytics reports in the left column. Each section is divided into different tabs and clicking on a tab will expand it to show more options.
- Real-time This report will show you a real time view of your traffic.
- Audience tab will show reports to help you understand your users.
- Acquisition reports explore where your users came from.
- Behavior reports summarize what your users do after they arrive on your site.
- Conversion reports show how well you’re doing against your goals.
Making the Most out of Google Analytics
Google Analytics is an incredibly powerful tool with tons of awesome features. Some of them are quite obvious and easy to use, others require some additional setup.
Here are some of the resources that will help you make the most out of Google Analytics reports.
- Track user engagement in WordPress with Google Analytics
- Track WooCommerce customers in Google Analytics
- Track outbound links in WordPress
Google Analytics works best with Google Search Console (formerly Google Webmaster Tools). It allows you to see how your website is doing in search results. See our complete Google Search Console guide to learn how to use it to grow your website.
We hope this article helped you learn how to install Google Analytics in WordPress. You may also want to see our ultimate WordPress SEO guide for beginners.
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.
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?…
You are correct unless you create a child theme.
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??
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.
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
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
Google Analytics does not any longer look like what you show. They have changed it.
Thank you for letting us know about that update, we’ll look to update our article when we are able
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
Glad our guide could help
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 ?
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.
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.
You would want to try removing line 1 from the code in our guide for that specific error.
Thanks a lot for sharing on how to install Google Analytics.
Glad our guide was helpful
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.
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.
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!
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.
Super Helpful!!!! thanks!!
You’re welcome
Can you set up Google Analytics for multiple websites with the same Google account? And how?
In your Google Analytics Admin section, there is the option to add a new account that would be your new site.
Thanks! Exactly what I needed. ✌
You’re welcome, glad our guide was helpful
Thank you for the post! Your content helps me a lot in setting Google Analytics up!
You’re welcome, glad our guide was helpful
after following the instructions I got this error showing up:
syntax error, unexpected ‘<', expecting end of file
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.
Very helpful for the beginner
Glad you found our guide helpful
Thanks.
Great information
You’re welcome, glad our guide was helpful
Thank you for making this well thoughtout content. For FREE!
You’re welcome, glad you’ve found our content helpful
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.
You would want to start by clearing the caching on your site for the most common solution to this issue.
Excellent instructions. Thanks a bunch!
You’re welcome, glad our guide was helpful
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
Glad our guide was helpful
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
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/
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.
Using either of those methods would automatically add the code to your new posts and pages
Thanks for this helpful information. I want to install Google Analytics without Google Tag Manager. Where do I find the code for this please?
You would not add Google Tag Manager if you do not want to use it on your site.
Thanks for this detail explanation. Very helpful
You’re welcome
OMG so helpful and easy! Follow all the steps now I am set up! Thanks a bunch
You’re welcome
Very helpful. The steps to take were clear and understood.
Glad you found our article helpful
Thanks, I dont know alot about any of this but I installed google analytics with no problem by following your tutorial.
Now on to something else!
Glad our guide was able to help
Super helpful; thanks brother.
You’re welcome
Thank you! Very useful video. I used the Headers and Footers Plugin as I prefer to have google analytics app on my phone and I can view all websites from that.
this article was super helpful and contained everything I wanted to know. thank you
You’re welcome
Can’t wait to learn more.
We hope our guides can help
Thank you! This was super easy to follow and I was able to setup Google Analytics using Monster Insights very quickly following this guide.
You’re welcome, glad we could help simplify the process
It’s quite very good and useful
Thank you, glad you found our guide helpful
Hey! Amazing tutorial.
But while going with the 3rd method I faced an error which says :
Your PHP code changes were rolled back due to an error on line 1006 of file wp-content/themes/oceanwp/functions.php. Please fix and try saving again.
syntax error, unexpected ‘<', expecting end of file
Please help.
Your functions.php likely did not close its PHP, you should be able to add the code without the first line
Yep, that worked for me – removed ‘<?php' and the error dispeared.
Thanks..
Hi. My plan is free. It doesn’t support plugin installation. In that case, what can I do for using google analytics?
For WordPress.com sites, you would need to check with the support documentation for what they allow at the moment.
Hello,
I did instal Google Analytics correctly and it works perfectly!
But it is tracking my own IP as well.
Is there an solution to this problem?
I couldn’t found it anywhere.
This is one of the reasons why we recommend MonsterInsights, it should filter out your own visits without needing to set up a filter in Google Analytics.
I follow the steps exactly from the video tutorial, but I can’t update my file of theme editor, it says this:
Your PHP code changes were rolled back due to an error on line 83 of file wp-content/themes/neve/functions.php. Please fix and try saving again.
syntax error, unexpected ‘<', expecting end of file
We would recommend taking a look at our guide on copying snippets from the web below for the most common reasons for an issue like that:
https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/
Thank you for all of this, G Analytics is something I struggle with implementing as my brain shuts down at the thought, but you’ve made it more clear to me!
I’m using Insert Headers and Footers to paste the code, but I already have code on there for other stuff – can I paste code directly below?
Yes, you would add the new code below your current code
Thank you. I am just launching my website and you have been such a great resource. This quickly explained how to set up Google analytics in my website and I love that I don’t have to put code on each page as I was very confused on the google analytics page.
Glad our guide was able to simplify the process for you
thannks a lot man ..really helped alot
Glad our article was helpful
Really cannot find a good site where to explain how to add the Google tracking code to a wordpress site without plugin. Why plugin is needed anyway? IS there any other website apart from this wordpress where i can add the hmtl code i want without having to purchase, add plugin, update my account or anything like that? Man, they make it complicated
It sounds like you are on WordPress.com which would be the main factor for that issue, you may want to take a look at our comparison here:
https://www.wpbeginner.com/beginners-guide/self-hosted-wordpress-org-vs-free-wordpress-com-infograph/
WordPress.com requires one of their paid plans currently to connect Google Analytics
just to say thank you
You’re welcome, glad you liked our guide
Hello,
I’m using #3 to add GA in WordPress Theme. I just wanted to know if add code in header.php file then do I also have to add via functions.php? Will only update in header.php work?
You would use one of the methods, you would not want to use both and it is personal preference on which method you use
Thank You so much for the information!
You’re welcome
Thank you so much for the information! You mention it takes some time for Google Analytics to connect to the website. How long is that process generally? My Siteground dashboard shows sessions and pageviews, but GA still shows zero.
Thanks for your help!
normally 24-48 hours but times can vary
Will this plugin report the hits back to my main analytics (web) account? Because I’m unable to paste the analytics code on my web pages.
Will like to hear your response, Thanks.
As long as it is connected it will send the information back to your Google Analytics account.
Thanks for sharing this topic. It’s help a lot.
You’re welcome, glad you like our guide
Thanks for your excellent guides.
You’re welcome, glad you like our guides
Thank you for the information! I have Google Analytics, but didn’t know how to read it. You cleared that up here. Thanks
You’re welcome, glad our guide was helpful
Thank you for continually posting articles and videos to help us walk through the process and set up great sites. I’ve been wanting to learn more about GA and this article and video were the perfect starting point for me!
You’re welcome, glad our guides are able to help you