Last updated on: May 15, 2020
Do you want to learn how to add Google Analytics to WordPress?
As one of the most popular tracking tools for most site owners, it’s a great way to get detailed insights into visitors’ behavior, event tracking, and more. But how do you get it set up for your website?
In this article, we’ll show a number of ways you can add Google Analytics to your website.
Why Google Analytics is Important
When you create any website, one of your biggest goals to get more website traffic. Google Analytics helps you make decisions on how to reach those goals by showing you the statistics that matter to your website.
That stats recorded in analytics include:
- Visitor stats: who visits your website, their geographical location, which browsers they use, and more.
- Behavior stats: what people do on your website such as which pages they visit, how much time they spend on each page, and how many people exit your site on the first visit.
- Time stats: the time of day people visit, and which days see the most traffic.
- Referral stats: how people find your website such as through search engines, from websites linking to you, social media networks, and more.
- Interaction stats: how people interact with your site content, including the percentage of link clicks, and how easily people move from one page to another.
Using analytics for your website removes all the guesswork, and helps you focus on the data that matters. Then you can make data-driven decisions to improve your site, and grow your business.
Methods to Add Google Analytics to WordPress
To keep things easy to browse, we’ve summarized our suggestions for you. Simply click any of the options below to jump to your preferred method:
- Adding Google Analytics With a Plugin
- How to Add Google Analytics without a plugin
- Add the Analytics Tracking ID to a WordPress Theme
- Add Google Analytics With Google Tag Manager
The only thing we’ll assume is that you’ve already signed up for your own Google Account. If you haven’t done this already, you can go ahead and sign up for a new analytics account here.
Then come back and we’ll get to it.
Method 1: Adding Google Analytics to WordPress With a Plugin
For this method, we’ll be using a plugin to set up your tracking information. The best Google Analytics plugin for WordPress is MonsterInsights.
MonsterInsights is not only the easiest solution, but it also has heaps of advantages over manual methods which are:
- WordPress analytics reporting: Actionable data and insights within the WordPress dashboard
- eCommerce tracking: Set up tracking for WooCommerce, Easy Digital Downloads, LifterLMS, and MemberPress with 1 click.
- Affiliate tracking: Use Google Analytics reports in MonsterInsights to find out which affiliate links are getting the most clicks so you can maximize your revenue
- Download monitoring: See how many downloads your files are getting with custom reports
- Author stats: Find out traffic and engagement statistics for each individual author on your blog.
And you can do all this without having to know, or understand how to code.
Note: MonsterInsights used to be known as Google Analytics for WordPress by Yoast. WPBeginner’s founder, Syed Balkhi, acquired the plugin in 2016 and changed it to MonsterInsights. Now it’s part of their family of premium WordPress plugins.
To set up analytics with MonsterInsights, follow these simple steps.
Step 1: Download and Install MonsterInsights
When you purchased your copy, you will have received a license key that you can view in your MonsterInsights account area.
Copy that key and add it to the blank License Key area in WordPress. Then click Verify.
Step 2: Connect MonsterInsights
Once your license is verified, scroll further down the page where you’ll see 2 options labeled:
- Connect MonsterInsights
- Launch Setup Wizard
For this step, you’ll need to click the Connect MonsterInsights option.
After this, you’ll go to another page where you can log in to your Google account. Then you’ll see a message from MonsterInsights asking for permission to access your account.
To provide access, go ahead and click the Allow button.
On the next page, you can select the website you’d like to collect data for.
To complete the process click on the Complete Connection button and that’s it.
Step 3: View Your Reports from Google Analytics in WordPress
Now you can check Google Analytics reports directly on your WordPress dashboard.
To do this, click on Insights » Reports from within the WordPress admin area. You’ll then see the reports right on your screen.
And if you scroll down your page you can view more details including your top referrals, top posts and pages, top countries, bounce rate, and more.
Now, there’s no more logging into other websites to view your stats. Instead, the information you need to track visitors and make informed decisions about your site is all on your dashboard.
Method 2: How to Add Google Analytics Without a Plugin
For the next method, we’ll look at how to set up Google Analytics in WordPress manually without the need to use a plugin.
This is a useful solution if you’re comfortable with using code snippets and would prefer to track basic stats manually.
Step 1: Find the Analytics Admin Area
After logging into your Google Analytics account, you’ll be faced with your default dashboard.
To find your tracking code, click the Admin sign on the bottom left corner of your screen which is shown as a gear icon. After this, you’ll be redirected to the admin area.
Step 2: Locate the Tracking Code
Once you’re in the admin area, it’s time to locate your tracking code.
Under the Property column, you’ll see a list of expandable headings. Click Tracking info to expand the list.
Then select the Tracking code heading.
A new area of the screen will slide out to the right, revealing the information you need.
Step 3: Copy the Global Site Tag
For this method, you need to copy all of the site tag information. To do this, copy all of the code under the Global Site Tag (gtag.js) heading.
Next, you’ll need to log in to your WordPress dashboard and paste this code into your website header. Let’s see how to do that in the next step.
Step 4: Add the Tracking Code to Your WordPress Header
To add your Google Analytics code manually to your site header, you’ll need to edit your themes’ header.php file.
But if you go down this route, it’s important you add the code to a WordPress child theme rather than your main (Parent) WordPress theme. This is because your tracking code is overwritten in the parent theme every time you update the theme files.
You might be asking “Where do I put the tracking code in WordPress”?
Well, Google recommends you paste the code in the Header section.
To do this, locate your themes header.php file by going to Appearance » Editor.
Then scroll through the files until you find the right one and click to open and edit it.
Now paste your Google Analytics tracking code into the file right before the closing </head> bracket as shown below.
Then click Update File and you’re done!
Method 3: Add the Analytics Tracking ID to a WordPress Theme
For the next method, we’ll show you how to install Google Analytics in your WordPress theme. It’s actually pretty straight forward if you follow the steps we explain below.
Step 1: Copy Your Tracking ID
First, you’ll need your Tracking ID which you can find under Tracking Info » Tracking Code in your Google Analytics dashboard as we explained earlier.
Go ahead and copy the ID and move on to the next step.
Step 2: Add the tracking ID to the functions.php file.
To locate your theme’s functions.php file, head to Appearance » Editor from the WordPress dashboard.
Then scroll through your theme files until you locate the one labeled functions.php which is your Theme Functions.
Then add the following code snippet into the file, using your own tracking ID instead of ours.
Click Update File when you’re finished and Google Analytics should start working right away.
Method 4: Add Google Analytics With Google Tag Manager
Google Tag Manager is a tag management system (TMS) that lets you manage different tags on your website. It also helps you deploy different types of code like your Google Analytics tracking code without having to edit your website’s code.
To add Google Analytics with Google Tag Manager, follow these simple steps.
Step 1: Create a Google Tag Manager Account
First of all, you need to sign up for Google Tag Manager and then create a new account by entering an Account Name.
Now move on to the Container Setup. Here enter your Container Name which is your website, and select Web as your Target Platform.
Click Create to continue.
You’ll then be asked to agree to the Google Tag Manager Terms of Service. Click Yes. Then you’ll receive the tracking codes to add to your website.
Step 2: Add the Tag Manager Snippet to Your Header
The next step is simple. Copy and paste the code snippet into your header.php file in WordPress.
To do this, simply follow the steps we explained in Method 2.
Step 2: Add a New Tag in Google Tag Manager
To get Google Analytics connected to Google Tag Manager, start by clicking New Tag.
You can rename your tag if you’d like to and click the Tag Configuration icon to choose your tag type.
Then choose Google Analytics: Universal Analytics.
You’ll have to enter your Tracking ID, which we explained how to find earlier, and your Tracking Type.
For this example, let’s choose the Pageview tracking type.
Now under the section labeled Triggering, click the icon to open up the settings.
For adding Google Analytics you’ll need to choose the All Pages page view.
Now click Save and you’re done!
Analyze Your Data
Now that you’ve integrated your WordPress website with Google Analytics you can start checking your data.
However, it takes Google a while to collect and report the information to you through its dashboard.
So wait for at least 48 hours before you take a look at the collected Google Analytics data.
Once the waiting period is over, you can access your data by visiting analytics.google.com where you can even get a glimpse of your real-time stats.
Some of the information you can gather includes:
- Demographics – The age and gender of your audience
- Geographics – Visitor languages, locations, and time zone
- Behavior – New vs returning visitors, frequency, and engagement
But if you’ve used the manual method, you won’t be able to see any stats in WordPress. For this, we suggest using Method 1.
That’s it! If you liked this tutorial, you might want to check out our guide on how to put your WordPress site in maintenance mode. And if you’d like to know how to add a contact form to WordPress, take a look at this tutorial.
And don’t forget to follow us on Twitter to see our latest blog posts