How to Install Google Analytics in WordPress
There are many different ways to setup Google Analytics in WordPress. We will show you three different methods where the first option is the easiest and the last being the hardest.
You can choose the one that best suits your needs.
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).
MonsterInsights has both a free version and the Pro 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 Ecommerce 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, and if you want to learn how to install and manage WordPress plugins, see our WordPress basics course.
Upon activation the plugin will add a new menu item labeled ‘Insights’ to your WordPress admin menu. You need to visit Insights » Settings to configure the plugin settings.
On this screen, you need to click on ‘Authenticate with your Google account’ button to connect Google Analytics with your WordPress site.
This will bring up a popup where you will be able to authenticate with your Google Account.
Click on ‘Next’ to continue.
Now you need to click on ‘Click to get Google code’ button.
This will bring up another popup with the message ‘MonsterInsights would like access to your Google Analytics data’.
Click on the ‘Allow’ button to continue.
The authentication popup will now show you a line of code which you need to copy.
Next, you need to enter this code in the MonsterInsights popup and then click on ‘Next’ 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 next button to continue.
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 report inside your WordPress dashboard. Simply visit Insights » Reports page to checkout a quick overview of your analytics data.
You can go also go in the Tracking tab to customize the tracking settings based on your needs:
Note: MonsterInsights was formerly known as Google Analytics for WordPress by Yoast.
2. Insert Headers and Footers Plugin
This method is not as 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.
Upon activation, you need to visit Settings » Insert Headers and Footers page. Here you need to paste the Google Analytics code that you copied in step 4 into the headers section.
3. Install Google Analytics in WordPress Theme
This method is for advanced users only who are familiar with 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.
Add code in header.php file
Simply edit the header.php file in your WordPress theme and paste the code you copied in step 4 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 code to every page on your WordPress site.
You will need to add this code to your theme’s functions.php file.
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 and clicking on the reporting tab.
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.
- 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.
We hope this article helped you learn how to install Google Analytics in WordPress.