Estimated Reading Time: 7 Minutes
Measuring website user behavior whether it is to consume content or make a purchase is vital which is why I put together a post on how to add Google Analytics to WordPress.
Why WordPress? WordPress is a super popular platform, and according to some of the most recent stats, 30% of the web is powered by WordPress.
That coupled with over 40 Millon sites using Google Analytics to track site visitors means that there is a shi**oad of Google Analytics WordPress out there.
Since a proper Google Analytics install is critical to accurately tracking users, I provide three different approaches on how to Add Google Analytics to WordPress.
How to Add Google Analytics to WordPress Using a Plugin
The first and easiest way to install Google Analytics on WordPress is to use a Google Analytics WordPress plugin. You can go two ways with this approach.
If you want to get the tracking code in place and are not looking for any additional features, you can use GA Google Analytics a Google Analytics WordPress plugin built and maintained by Jeff Starr.
This is a simple way to get up and running quickly.
However, there are more robust Google Analytics WordPress plugin options available if you are looking to pull in reporting dashboards directly into your WordPress site.
Many of these Google Analytics WordPress plugins also have granular tracking and some customization features that can be applied.
Keep in mind that the more robust tools require a more extended setup and also work on a freemium pricing model.
The drawback with relying heavily on plugin functionality is potential compatibility with your site, lack of unique customizations and dependence on the plugin working correctly with the Google Analytics API. (future proof)
How to Add Google Analytics to WordPress with a Header & Footer Script Inserter
You can also add Google Analytics to WordPress by placing the Google Analytics script in one of these plugin fields.
That is if you are not working with a framework, i.e. Genesis or Thesis which already have a script field built into their Framework. For example, Genesis provides the following field under settings.
If you are working without a Framework and are using the native WordPress install, you can use a plugin for adding WordPress Google Analytics script.
For example ‘ Head and Footer Scripts Inserter’ allows you to Hook into the Header and Footer sections of your site adding custom tracking scripts.
Alternatively, if you can access your functions.php file and are comfortable making edits you can always Hardcode the Google Analytics WordPress Script in the Functions File.
This is pretty straightforward, and you can reference these sources for the specific code:
Install Google Tag Manager on WordPress
For the third option, you can install the Google Tag Manager plugin then install Google Analytics via GTM to Add Google Analytics to WordPress.
This is the more robust and most flexible version.
If you ask me it is the best approach since you are setting yourself up to be highly flexible with the ability to customize your tracking on an ongoing basis.
You are also not limited to Google Analytics tracking and can install other essential tracking snippets such as the Facebook Pixel.
The plugin I use for this is
DuracellTomi’s Google Tag Manager for WordPress it is super powerful works seamlessly for Google Tag Manager and can even push page meta info into data layers.
I will cover the basic set up for the Google Analytics tracking here, but these set of tools have so much more to offer.
So if you are an expert knock yourself out 🙂 and if you are a beginner then as you learn and expand your tracking and analytics expertise you are already set up for success.
Setting Up The Google Tag Manager Plugin
Ok let’s get started:
(The assumption is that you already have a Google Analytics and Google Tag Manager account and of course a WordPress site)
First, go to the plugin page and download the plugin file.
Then upload the plugin to your WordPress site and activate it.
Alternatively, you can search for the plugin in the directory and install it that way.
Once the plugin is active, let’s go over the basic set up.
You can find the plugin under Settings > Google Tag Manager
First Enter your GTM Container ID
The other tab I will cover briefly is Posts under the Basic Data tab. This writes data layers to the source code that you can then use in Google Tag Manager.
You can see I have Post type, Category and Tags selected.
Pulling these into the data layer allows me to create custom firing rules in Google Tag Manager.
You can learn more about the plugin and in the support section.
Setting Up Google Analytics With Google Tag Manager
Since this post talks about how to add Google Analytics to WordPress, I will include the basic set up of Google Analytics in Google Tag Manager. For a more comprehensive guide you can reference this complete guide to adding Google Analytics to WordPress from Tommy Griffith.
First, go to your GTM account, click create a new tag and give it a name.
Choose Universal Analytics as the Tag Type.
Set you Track Type to Pageview Enbabel the Override Setting and enter your Google Analytics ID or Constant Variable containing the ID.
Now add the trigger to fire on all pages.
Click save, and your Tag should be all set.
Before you publish hit preview and make sure the tag is firing correctly.
If all looks good, you can submit and publish.
Note: To validate tracking I always use the Google Tag Assistant chrome extensions. Well worth the install 🙂
If you cannot measure how people are interacting with your site, then you do not know what actions are driving conversions.
Besides, if you capture inaccurate user data, you could be making misinformed vital decisions that negatively affect conversions.
Tracking users is essential but tracking users accurately is critical.
What set of tools have you made use of to Add Google Analytics to WordPress?
Do you rely on a Google Analytics WordPress plugin or find them too limiting?