How to add Google Analytics to your WordPress website
August 2. 2019
Keeping track of your website traffic is an essential part of gaining valuable insight into customer behavior. One of the best ways to achieve that is to add Google Analytics to your WordPress site. In this article, we cover the easiest ways for anyone to incorporate Google Analytics into WordPress.
What is Google Analytics and why is it so important?
Before vexing into the process of installing Google Analytics, we first need to define what it is and how it helps your business.
Google Analytics provides insight into your customers
With a presence on over 50 million websites around the world, Google Analytics is a web analytics suite that helps you analyze your web traffic. The foundation of how it all works is in the JavaScript code that is added to your page, which then allows Google to track activities of visitors on your site. Here are the fundamental questions that your Google Analytics account answers:
- Who is visiting your website? And information based on the geographical and technical information of your site visitors.
- What do your visitors do once on your website? Discover how long people stay on your website, which pages they visit, your bounce rate, etc.
- When are they coming by? Add Google Analytics to your WordPress site to learn the most common time frames for your visitors.
- How do they find your site? You are also able to learn where your site visitors are coming from and how they found your website.
- How do they interact with your content? Learn whether people follow the links in your content and how they interact with it.
You can then use the information you gather from these answers to optimize your website.
Optimizing your website with the information you collect
You need to find a way to use all the information that you gather about your target audience. But how does it benefit your WordPress website maintenance efforts?
- For starters, you can upgrade your website to answer the needs of its visitors.
- Differentiate between the better and worse source of traffic for your WP site.
- Adjust your content strategy accordingly to meet the expectations of online users.
- Monitor the effectiveness of marketing campaigns.
- Boost the quality of your website by identifying and improving your worst-performing pages.
When you sum it all up, using web analytics helps you eliminate guesswork and make planned decisions about your site instead of relying on gut feeling. And the best part about Google Analytics is that it is a free and commonly-used tool for such goals.
Adding Google Analytics to your WordPress site
Before you use Google Analytics to measure the traffic on your website, you first need to install it. And to achieve that, you have three different methods to choose from:
Option A: Insert the code into header.php
Adding the tracking code to your header is one of the easiest ways to implement it on every page of your website. And this is all the easier with WordPress websites, where most standard themes have a header.php file to arrange the header section.
The only precaution you need to take here is to ensure the use of a child theme before attempting any header updates. That way, you don’t risk losing any modifications when you update your central WP theme. Once you manage to create your child theme, just copy your main theme header.php and start toying around with it.
- Copy and paste the Google Analytics tracking code into it and then close the </head> bracket in the code.
- Important tip: don’t forget to wrap the code in <script> brackets. If you fail to do so, browsers won’t be able to recognize it.
- Save and upload the file back to your server.
Option B: Add Google Analytics to your WordPress site via functions.php
Using the functions file is another way to manage to install Google Analytics to your WP site. It works the same as described in option A. Rather than utilizing a header.php, you can simply edit your child theme’s functions.php file. Save, upload, and from that moment, Google Analytics should start working.
Option C: Use a Custom Plugin
The third option to add Google Analytics to your WordPress site is to create your plugin. That way, you will be able to switch the tracking option on and off from the WP backend. Additionally, this enables you to keep the tracking code even if you decide to change your WP themes.
However, before you get into this option, you need to make sure that the wp_head hook is inside your header.php. Once you complete this, you need to create a new PHP file. Something similar to nick-google-analytics.php, but under a new text editor file.
Just don’t forget to replace the sample tracking code with your own. That means replacing everything between <script> and </script> if you want it to work. Once you’re done with it all, you just need to save the file and upload it to wp-content > plugins. And once all that is complete, it’s just a matter of activating it from the WP back-end like any other plugin.
How to add Google Analytics to your WordPress site with a plugin
As the most popular plugin for this particular purpose, we will explain the installation of Google Analytics for WordPress by MonsterInsights. With over two million downloads and installations, it is a standard, easy-to-use plugin. The Premium version is even GDPR compliant. So, here are the steps you need to follow to install it:
1. Install the plugin
The first step in using any plugin on your WordPress website is the installation process. So, you first need to go to Plugins > Add New. You can find the plugin by name search – just type in google analytics.
Once you find it, all you need to do is select Install Now and download it. Once done, simply hit Activate.
2. Connect to Google Analytics
Once the plugin has been activated, you will see a new menu item on your site’s dashboard – Insights. Click here to go to the Settings menu. Once there, you will need to Authenticate with your Google account. Once you choose the account you want to sign in with, Google Analytics will request access to your data.
Make sure to allow this, so that it can work properly. Select an earlier profile that you want to track and complete the authentication when you have done so. Once you complete all this, you will be redirected back to your site and voila – you’re done!
3. Adjust the tracking settings
Once inside the plugin, you can make changes to how the app tracks your visitors via the Tracking tab. Here are the basic functions:
- Engagement— enables you event tracking (meaning clicks on the links) while ignoring visitors with user roles.
- Demographics— you can use it to switch on demographics and interest reports, as well as IP anonymization.
- Permissions— allows you to control who on your site can view the reports and change settings.
4. Check the reports
The best part about this Google Analytics plugin is the fact that you can check the data directly in your WordPress dashboard. And you can see it all under Insights > Reports. Bear in mind that it takes 12-24 hours before data from Google Analytics starts appearing. So, even if you don’t see it immediately, simply check back later.