So you want Google Analytics on your WordPress site? And you don’t know which plugin to use? Look no further.
It was a little surprising in 2018 when I went through my old sites. I had been a little inconsistent with my analytics plugins over the years. Some had an analytics plugin, some had a tag manager plugin, some had tag manager code added to the theme. This post contains the method I prefer, and recommend to everyone.
Three years ago at a Google Conference in Sydney, every speaker at the conference said that if you weren’t using a tag manager to install analytics, you were crazy. It hasn’t changed. And the tag manager I prefer is the free Google Tag Manager.
So when planning a new website (or updating an existing one), these are the steps.
Create a Google Analytics account.
Google Analytics has a hierarchical structure of Account, then Web Property, then View.
The Account equates to a company, the Web Property equates to a website, and the View is how you want to report it.
So all of my personal sites are in my Geekmum Account. Then I have one Web Property per website (eg one for halloween-australia.com, one for christmas-australia.com, one for mistressofmocktails.com).
And within the Web Property, I usually have two Views: one for clean production data, with filters to exclude my personal traffic; and another unmodified raw data. My personal naming standard is to append a number after the url so that it sorts in order. eg “mistressofmocktails.com.au – 00 clean data” and “mistressofmocktails.com.au – 99 raw data”.
Google Analytics is available at analytics.google.com.
The most important thing you get when setting up your Google Analytics account/property is the UA tracking code, in the format UA-xxxxxxx-nn
Check the Google Analytics settings.
If you don’t check the default GA settings, you may not be getting what you expect.
Here’s a screenshot of the View settings for one site:
Things to look at:
View Name – have a clean data view
URL – check that you have http or https correct
Time zone – check that you have the local time zone
Default page – shouldn’t be necessary for WordPress
URL parameters – again, shouldn’t be necessary for WordPress
Current – check current currency
Bot Filtering – select the tickbox
Site Search – enable if you use it
Query parameter – by default WordPress uses s
I like to strip out the query parameter.
I like to filter out my IP address from the clean View.
And to check Audience/Technology/Network/Hostname to make sure there isn’t any hostname spam present.
If so, then I add a filter to only include a hostname with a regex matching say mistressofmocktails
You might have a goal of a contact form submission, newsletter signup, product sale, download, share, a visit to a particular page, or a particular custom event. You can also define a goal based on the time on site, or pages per session. Regardless, you need to setup goals inside the Google Analytics account. That’s how you’ll measure the success of each traffic channel.
Setup the Google Tag Manager Account (GTM)
GTM is available at tagmanager.google.com.
As with Google Analytics, there is a hierarchical structure – of Account, then Container.
An Account can have multiple Containers, with each Container usually matching a website.
Create the new Container, and you will be provided with GTM tracking code to add to your WordPress site. You will do that later on when adding the plugin to the WordPress site.
The GTM tracking code will have the format GTM-xxxx.
Setup GTM Variables
GTM comes with a number of variables that can be enabled and configured.
It’s good practice to setup your Google Analytics tracking code as a constant in GTM, so that you can use it later on in multiple tags. GTM has a special variable called the Google Analytics Settings variable, which allows you to configure GA settings in one place. This includes enabling display marketing – which is necessary for setting up remarketing lists in Google Analytics later on.
Setup GTM Tag for Google Analytics
Now you have everything you need to setup a tag inside Google Tag Manager, that will add Google Analytics to all the pages on your site. Create a tag called GA-UniversalAnalytics, add your GACode, set it to be triggered on All Pages, and hit save.
Don’t forget to Publish the Container, when you’ve finished creating the Tags.
Add the GTM plugin to WordPress
My favourite GTM plugin for WordPress is by DuracellTomi. Over 100,000 people can’t be wrong – that’s how many have installed this plugin.
In the WordPress admin, simply go to Plugins, Add New, and search for DuracellTomi and click Install and then Activate.
Then navigate to the GTM Settings, and simple paste your GTM-xxxxx into the provided field.
There is one other area for configuring the plugin. It provides a number of options for how the GTM code will be added to your WordPress site – in the footer, in the theme, or dynamically injected.
If you’re feeling brave and have the ability to test it locally, I’d use the dynamic injection.
If you have a custom theme, I’d edit the theme to add in the extra line, as suggested.
If you’re feeling lazy, leave it at the default, in the footer.
This is not Google’s recommendation, as it means the site will load before it executes the GTM code, and may miss out on executing some tags, if people leave the page before everything has processed. However I’ve never had any problems with this approach. It will come down to how much traffic your site gets, and how quickly it loads.
But that’s all it takes. Your GTM plugin is installed on WordPress, your GTM and GA accounts were created, and there’s a GA tag inside GTM.
Test that everything works
I have a few Chrome plugins I use for verifying analytics.
GA Debugger – the official Google debugging tool. It can be toggled on and off in the browser window, and when combined with Chrome inspector tool, will show the actual GA code being sent to Google.
Google Tag Assistant – another official Google tag tool. Enable it, and refresh the page in the browser, and it will show what Google Tags are present and if they are executing correctly. In this case, it should show that both GTM and GA are present on the site.
Think about dashboards
Wait for some data to start accumulating in your GA account, and then you can start analysing it.
And even better, create a dashboard in Google Data Studio. But that’s another post.