Adding Google Analytics to WordPress can be as easy as installing and configuring a plugin, as efficient as customizing a theme, or as performance and scalable option using Google Tag Manager.WordPress continues to be one of the most recognized content management systems for website owners thanks to it’s easy-to-use publishing features, extensibility, and low-entry costs. Now that you have a WordPress website running, it’s time to know:
- How visitors are accessing your website
- Where are they are located
- Who they may be, and their interests
- What they are viewing
- Why they might be visiting your website
- As well as many other metrics and data that can help you learn about your website’s traffic
It doesn’t matter why you’re using WordPress, the next step is to know how well your traffic is working for you and how to create narratives to make it work better. Google Analytic has becoming the industry standard for website analytics thanks to it’s entry-level features, broad data aquisition, and simple user experience.
There are many choices on how to add this popular and robust website analytics platform to your WordPress website, and the option you choose is dependent on your skill level, time, and interest in performance.
This article will provide insight on what Google Analytics is, the options to install it on your WordPress website, and how to let your visitors know how Google Analytics is capturing their information for transparency.
This article will not discuss:
- eCommerce tracking
- Understanding Google Analytics metrics
- Full Google Analytics account optimization
- Other Google Product Integration
These areas will be written at a different time, or are already discussed in other articles on this website.
What is Google Analytics?
Google Analytics is the most widely-used website analytics tool for websites, not just for WordPress. The platform can track website sessions, duration, page visits, and various other metrics. Individually, these metrics can provide some understanding of what’s going on, but other metrics and reporting can be combined to create narratives that help you understand what is really occurring on your website.
The most popular aspect of Google Analytics is that it is free. Yep. Doesn’t cost you a penny. There is a paid version, but for 99% of users, the free version has all the features you’ll ever need, and even features you’ll never use.
The robust features and reporting of Google Analytics can get you lost in the weeds when you see how much the service can accumulate and display data.
Where did Google Analytics Come From?
I believe context is important. Google Analytics was purchased by Google in 2005 from a company called Urchin. Google has expanded their platform since then and it continues to be a free service that has conquered the analytics world.
Create and Setup your Google Analytics Account
1. Create a Google Account
The first this to do is to create a Google Account if you do not have one. Gmail is a popular service from Google and is among the most popular ways to use Google’s vast array of products and services. This would count as a Google account. However, you are not required to have a Gmail account or email address. If you have an email address that you’d prefer to use with Google’s products and services, that’s fine too.
Go to https://accounts.google.com/signup and either create your free Gmail account or use the email address you prefer. If you need help, check out this video:
Creating a Google Account Video
Note: There is no sound.
2. Create a Google Analytics Account
Once you’ve created a Google Account, now you’ll need to create a Google Analytics account. Go to https://analytics.google.com/analytics/web/ when logged in with your Google Account, and complete the steps. Here’s a video showing how it’s done:
Creating a Google Analyitcs Account Video
Note: There is no sound.
Account & Property Setup
You’ll be asked to enter the following:
- Account Name: This can be generally anything you want.
- Website Name: This will be the name of the first property in your Account. Typically, adding the domain name or website URL is the best option for single websites or first-time users.
- Website URL: This will be your website’s URL. Be sure to select between https and http, and then enter your website’s URL. If your website doesn’t use www, do not add it.
- Industry Category: Select the category that best resembles your website. This helps with benchmarking.
- Reporting Time Zone: What time zone are you in?
- Data Sharing: These are options to share your Google Analytics data within Google’s broader services. Typically, selecting “Google products & services” and “Benchmarking” is just fine.
- Click on “Get Tracking ID”.
Agree to Terms of Service
You’ll then be taken to a few Terms of Agreement Pages. It is recommended to read and understand these agreements to understand what information Google tracks.
Tracking ID
You’ll then be taken to the Tracking Code page of your Google Analytics account. You’ll always have an opportunity to re-visit this page. You’ll be given a Universal Analytics ID (UA) that starts with UA-. You’ll also see some HTML code that needs to be added ideally between the <head></head>
HTML code on every page of your website that you want to track. Don’t worry, we’ll get to adding this later.
Brief Overview of your Google Analytics Account
Creating an account will automatically create an Account, Property, and an All Web Site Data View. Here are the differences between an Account, Property, and View:
- Accounts have high-level management of settings, users, filters, and can view change history.
- Property(ies) allow you to house multiple websites under the account. Each website is considered a property. Under a website’s property, there are options to adjust broader aspects of the analytics code for the website. Consider your website a property.
- Views allow you to adjust how your property captures data. In most cases, you’ll want to have a few different views. This will allow you to filter out various IP addresses, hostnames, and other traffic, manage your content and channel settings, among other options that help you report, manage, and display data.
Creating a new View
As stated above, your first and only view when you start a Google Analytics account is the All Web Site Data view.In this instance, we’re going to create one extra view. We’ll call this “Filtered” and we’ll filter out our current IP Address. This way, we will not collect information when we visit or our website.
More on Filters
Filters allow you filter out various types of traffic. In the following steps, we only be filtering your personal IP address. You can exclude traffic from internet service providers, subdirectories, or even specific hostnames. This will be handy later on if you use other services that crawl or access your website.
Create a new View.
Use these settings to start:
- Reporting View Name: Filtered
- Reporting Time Zone: Choose your time zone
- Click “Create View.”
Adjust the View settings to ensure we’re filtering out known bots.
- Bot Filtering: Enabled
- Save.
Before we setup our first filter, we need to know what our IP address is. Go to Google and type in “What’s my IP address”
Come back to Google Analytics, and select Filters, then click on “Add Filter.”
Now you will enter the following:
- Select “Create new Filter.”
- Filter Name: IP Address
- Filter Type: Predefined
- Exclude
- traffic from the IP addresses
- that are equal to
- Enter your IP address that you found on Google from one of the previous steps.
Now, you’ll be able to browse your own WordPress website without Google Analytics capturing your visits as traffic.
We’ll come back to optimizing your Google Analytics account, properties, and views later in another article.
Installing Google Analytics on WordPress
There are many ways to install Google Analytics on your WordPress website. With so many options, there are various pros and cons. We’ll show three ways to add Google Analytics to your website; with a plugin, within your WordPress theme, and with Google Tag Manager, which can also be added within a plugin or theme.
Installing Google Analytics with a WordPress Plugin
There are no shortages for Google Analytics WordPress plugins available, and the competition is tight. Plugins are perfect for entry-level users who just need the basic setups. Below are a few of the most popular Google Analytics plugins for WordPress.As the comparison table shows above, among the pros of using a plugin is that they are east to install and basic functionality is free, with upgrade options to open a vast array of options.
Among the cons is that it’s another plugin that you’re introducing to your website, potentially slowing it down, increasing security vulnerabilities, may break or be incompatible with other plugins, or break functionality upon upgrade.
Pros and Cons of using Plugins
Pros | Cons |
---|---|
Easy to install | Another plugin, might slow down your site |
Vast array of options | Needs to be updated |
Free and Premium options | Some options require premium purchases |
Security implications | |
May break with updates |
Most Popular Google Analytics WordPress Plugins
Google Analytics Dashboard Plugin for WordPress by MonsterInsights
This plugin was originally a Yoast product – the same company that brings you the popular Yoast SEO WordPress Plugin. A few years ago, the plugin was sold to MonsterInsights the same team behind WPBeginner.
Since then, the plugin’s more advanced features have been split between a free and paid version. The free version provides plenty of opportunities for intermediate tracking with Google Analytics. However, the paid versions are stupidly over-priced and don’t provide the level of services expected at that price point.
At the end of the day, this plugin does the job just fine.
Google Analytics Dashboard for WP by ExactMetrics
This Google Analytics WordPress plugin is also also by the same company behind WPBeginner and MonsterInsights is this plugin. Yep, this plugin was acquired by Syed Balkhi in May 2018. It’s strange that a company would choose to acquire two separate Google Analytics WordPress plugins, essentially cornering Google Analytics WordPress plugin market. In hindsight, it’s not a good idea for a free plugin that provides the same features that MonsterInsights is offering a exorbitant prices to run amok.
At this time (July 2019), this plugin continues to provide a robust set of features that the MonsterInsights version only offers but at no charge. However, be prepared for this plugin to either be merged into the aforementioned MonsterInsights version or having more advanced features placed under a premium version. Get it before it’s locked down.
The Rest
The remaining Google Analytics plugins for WordPress offer more or less of the same thing, and there are tons of choices. Unfortunately, to have full control over how Google Analytics is installed and setup on your WordPress website requires a premium or professional version of a plugin.
Installing Google Analytics without a WordPress Plugin
If you’re looking to reduce your server’s load with one less plugin and you feel comfortable with adding Google Analytics to your WordPress website at your theme’s template level, this method is your best bet.There are two additional options in this situation. You can add the code provided in the Tracking Code section of Google Analytics to your header.php file the safer option, or to your functions.php file the cleanest option.
Pros and Cons of using a Theme
Pros | Cons |
---|---|
Free | Requires some comfort with working with code |
Learn to work with theme files | Might be over-written with theme updates |
Some themes provide native support | Some options require premium purchases |
Theme Options
Your WordPress theme may offer an area where you can either add your Google Analytics code, or just the UA code. The only downside to this method is it doesn’t give you an option to place the code exactly where you may want it to go, or their code implementation isn’t fully compatible.
Google Analytics Code in header.php
This method is the safest option and will allow you install the Google Analytics code directly between the <head> </head>
HTML elements, which is where Google Analytics prefers for it to be installed.
Simply navigate from your WordPress Dashboard to Appearance > Themes > Editor, and then find the header.php file and click on it. In there, somewhere before the </head>
HTML element, you can copy and paste the Google Analytics code provided in the Tracking Code page in Google Analytics. Save and test. It will look something like this:
Boom. You’re done.
Google Analytics Code in a WordPress Theme’s functions.php
This option can be a little riskier, and is the preferred method if you want a really slick, performance-focused website. However, if you miss something you’ll get the infamous WordPress white screen of death. I recommend making a backup of this file, or your entire website for that matter, and be ready to move the backup functions.php file to your server in case your experience an issue.
Using this route essentially creates a new action that places the code on the page in a specific spot. The benefit to this method is that you can move this action around as you need to in case other scripts or code needs to be added before or after it.
Simply navigate from your WordPress Dashboard to Appearance > Themes > Editor, and then find the functions.php file and click on it. At the very bottom of this file enter the following code and replace the UA code with your own unique UA code.
Installing Google Analytics with Google Tag Manager and WordPress
The previous methods work well. However, there’s another advanced option that might benefit you if you plan on expanding the amount of scripts that appear on your website, such as Facebook Pixel or other marketing and tracking codes.The biggest benefit to this option is that when you need to install more tracking code on your website, you don’t need to install that code using a plugin or in your WordPress theme’s template files, which as stated earlier, is risky.
Instead of adding just Google Analytics code, you’ll add Google Tag Manager code. Google Tag Manager allows you to create various containers that contain scripts or code that can be executed based on various triggers. Additionally, the Tag Manager code loads asynchronously, which means it loads in parallel to your website’s other requests. If you installed multiple tracking codes directly on your website, each script would be loaded one-by-one, slowing down your site’s loading time.
Pros and Cons of Google Tag Manager
Pros | Cons |
---|---|
Free | Need to add as a plugin or in a theme |
Install other tracking scripts | Can be complicated |
Lightweight and fast | |
Use the same Google Account |
Unlike Google Analytics, Google Tag Manager has two sets of code that needs to be added to your website. Once set will be added within the <head></head>
HTML elements, and another set right after the open of the <body>
element. This means you’ll need to edit two WordPress theme files, or just your functions.php file.
Create a Google Tag Manager Account & Publish Your First Container
When you first visit Google Tag Manager, click on “Create Account”.
On the new account setup page, you will enter in your:
- Account Name
- Select your Country
- Container Name
- Choose “Web”
- Click “Create”
You’ll now be presented with two sets of code. The first will be added between the <head></head>
HTML elements and sections on your WordPress website. Please see the code below to learn how to install that code on your website.
Next, you’ll create a “New Tag.”
You will choose a Tag Type. In this instance, you’ll select, “Google Analytics – Universal Analytics.”
Now, you will change the name of the Tag to “Google Analytics”, and click on the Tag Configuration edit button.
With the Tag Type already selected, you can use these settings:
- Track Type: Page View
- Enable ovverriding settings in this tag
- Enter your Google Analytics Tracking ID Code. Remember, this starts with the UA-
You’re welcome to review other settings and adjust to your needs.
Next, you will choose to add a new Trigger.
Because you selected Google Analytics earlier, a trigger named “All Pages” with a Type of “Page View” is avaialble for you to select. Go ahead and select it.
Save the New Tag.
Submit your Workspace. and add optional description.
Write an optional, informative description about your workspace and version. Then click “Publish”.
Last, you’ll be presented with a result page of your publish.
Google Tag Manager Code in functions.php
Next, we’ll install the code. Again, we’re presented with the option of adding this code with a WordPress plugin, or in theme files. However, for simplicity, we’ll simply use a functions.php file.
Enter the code below in your functions.php file and replace the XXXXXX with your GTM– code in both places.
It’s better to use this code which tells WordPress to place the necessary code in both places, rather than edit two files.
Save and Test.
Create a Privacy Policy Page on WordPress
You might thing that we’re done, but to be fully transparent, comply with most government regulations, and even Google Analytics’s terms of service, you need to let your visitors know that you are using this service which collects data from your visitors in a Privacy Policy page.
If you’ve installed WordPress recently, you’ll automatically have a Privacy Policy page created to help you get started. Feel free to review my own Privacy Policy page and copy and adjust that information to your needs.
Testing Google Analytics and Google Tag Manager with Google Tag Assistant
Other than checking your website’s source (usually Ctrl + C on Windows, Command + U on Mac, or right-click and “view source” on most browsers), you can also install Google’s Tag Assistant on Chrome.
This browser extension helps you check to see if a particular Google services’ code is installed correctly on your website or any website for that matter. Not only does this work with Tag Manager and Google Analytics, it also works with Google Ads too.
Enjoy Google Analytics on Your WordPress Website
It’s all over! You did it!
Now go forth and create great content on your website and share it with the world. You’ll start seeing data appear in your Google Analytics account soon.
Next, learn how you can either optimize your Google Analytics settings for more accurate data capture and what your Google Analytics data means and how to take action.