As a new WordPress blogger you’re going to need to understand how visitors interact with your blog. You can’t do this with any degree of accuracy without using tools. Without doubt, one of the first tools you should employ when you’ve set up your WordPress blog is Google Analytics.
In this guide, I’ll explain how to add Google Analytics to WordPress. This will help you begin tracking visitor behavior on your blog and give you access to data that’ll help you understand how your blog is growing and how you can improve things.
I’ll tell you how to add Analytics to WordPress in 3 ways:
- Editing WordPress files directly.
- Adding Google Analytics code to your WordPress Theme (if it’s supported).
- Using WordPress Plugins.
Each of these approaches will result in data being sent to your Google Analytics account, but there are advantages and disadvantages to each.
Before you can take advantage of this post, you’ll need to set up a Google Analytics account and generate your GA Tracking Code.
Adding Google Analytics Directly to Your WordPress Header File
Since WordPress uses a series of different files behind the scenes to build your pages, it’s entirely possible to manually add Google Analytics code directly into your WordPress theme files.
One of the files WordPress uses is called header.php and this is the file where you’d likely need to add your GA code.
Most WordPress header.php files include the opening <head> and closing </head> html tags. You would insert your tracking code after the opening <head> tag, since Google specifies that’s where it should appear.
You can find header.php in your WordPress admin (under Appearance > Theme Editor) and directly on your hosting server in your theme directory (/wp-content/themes/yourtheme/header.php).
However, I’ll issue a strong word of warning. Just because you can do something, it doesn’t mean you should. You should never edit theme files directly but instead create a WordPress child theme and edit your files there.
If you don’t use a child theme and you edit your theme files directly, any changes you make will be overwritten when you update your theme. Furthermore, if you make a mistake when updating theme files, you may break your WordPress theme and render your blog unusable… nobody wants that!
The advantages of adding Google Analytics code directly to your WordPress header file are:
- It’s relatively simple.
- There’s little overhead on page load.
However… the disadvantages can be:
- A broken blog!
- Your header.php file might be overwritten if your don’t use a child theme.
My recommendation is NOT to use this method unless you use a child theme and are comfortable editing WordPress theme files.
Adding Google Analytics Tracking Code to Your WordPress Theme
It may be that your WordPress theme includes provision to add code to your blog from within your admin interface.
For example, I use the Genesis Framework. Fortunately for me in terms of this tutorial, I’m able to add code to various areas of my blog through an admin function in Genesis. Of course, your theme may not have this functionality and if it does it’ll possibly work a little differently.
That said, this is how it works in Genesis…
How to Add Your Tracking Code in the Genesis Theme
Appearance > Customize > Theme Settings > Header/Footer Scripts
When you click the “Header/Footer Scripts” option, you’ll be presented with an area where you can input your Google Analytics Tracking Code.
You’ll need to add your Analytics code in the “Header Scripts” section and click save.
The primary advantages of using the existing functionality of your theme to add your Analytics code are:
- It’s simple and quick.
- You needn’t install a plugin so there’s no potential impact on page load speed.
- It’s free.
- You don’t have to edit your theme files directly so there’s no risk in breaking your blog.
As I say, this functionality may or may not be something that’s available in your theme. If it is available, you may have to access it through a different menu path than I’ve shown for my Genesis WordPress theme.
How to Add Google Analytics to WordPress Using Plugins
Plugins are usually the first place we go to look for adding functionality for any requirement, and it’s probably no different when considering setting up Analytics tracking.
Of course there are advantages to using plugins:
- They do all the heavy lifting for you, and you don’t need to be technically confident to install them.
- Most plugins can be running in minutes.
- Many are updated and supported well.
However, there are disadvantages too:
- It’s not a given, but some plugins will slow down your WordPress blog.
- Free plugins might not be supported.
- If a plugin is not supported it may become a security vulnerability.
Notwithstanding, plugins remain a favorite way for most WordPress users to extend their blog.
There are dozens of WordPress plugins that will add the GA code to your blog. I’ll start by introducing some free “no fills” plugins that will get Google Analytics tracking up and running. Afterwards, I’ll move on to paid plugins that give you bells and whistles!
Free WordPress Plugins
Site Kit by Google
Site Kit is a WordPress plugin developed by Google to pull insights from its toolset into your WordPress blog. This means you can not only connect it to Google Analytics, but you can link it to other Google tools such as Google Search Console, PageSpeed Insights and AdSense.
You simply have to install Site Kit, activate it and then go through the plugin set up steps to connect it to your Google Accounts. Once connected, you’ll see all the data from the Google accounts you’ve connected in a new area in your WordPress Admin Dashboard.
GA Google Analytics
GA Google Analytics is a freemium plugin… the pro-version you’ll have to pay for but you get the functionality to add GA code through the free version.
The free version will populate your GA tracking code across your blog so you can see your stats in Analytics. The pro-version pulls everything into your WordPress Dashboard so you can see everything in one place.
Insert Headers and Footers
Insert headers and Footers is a basic, free plugin developed by WPBeginner. When installed and activated, it creates an area in your Admin Dashboard to add code into your header and footer areas. As such, if you only want to add Google Analytics tracking and require no flashy other tools, this could be just what you’re looking for.
You can also add any code you like into the header and footer, not Just Google Analytics tracking. So if you’re looking for something simple, this is a much likely a much better approach than editing WordPress theme files, where you risk fouling up your blog.
Paid WordPress Plugins
Now we are into the realm of paid plugins, MonsterInsights is perhaps one of the most popular to handle the tracking side of Google Analytics. As it’s a premium plugin it also offers all sorts of fancy functions and whizz-bang features.
The plugin builds a new area in your WordPress dashboard, which pulls your GA data into it. But more than that, MonsterInsights also shows you stats on:
- File downloads, for those with lead magnets.
- Ads tracking to analyze ad placement and performance.
- Referral and link tracking.
- Form tracking to help you determine the performance of your information captures.
MonsterInsights also supports privacy regulations compliance for GDPR (EU), CCPA (US), PECR (UK), PIPEDA (Canada), and more.
You get what you pay for I guess and you can see it does a lot more than just connect Google Analytics to WordPress!
ExactMetrics is another premium plugin to hook WordPress up to Google Analytics. It offers similar functions to MonsterInsights, which is not really surprising because they are kind of owned by the same parent company.
It too provides:
- File downloads tracking.
- eCommerce analysis.
- Affiliate link tracking.
- Form tracking.
- Privacy regulations compliance
Interestingly it also tracks:
- Telephone and email links.
As with MonsterInsights, it’s not cheap, but there are a variety of levels to choose from to cater for the size of your traffic.
The Google Analytics Dashboard by Analytify is a paid plugin but it’s a less expensive solution for adding GA to WordPress if you’re looking for more basic functionality.
Along with pulling your Analytics data into WordPress, it also presents social media stats and enhanced ecommerce tracking for WooCommerce stores to help you manage checkout abandonment.
So I’ve discussed 3 different ways to add Google Analytics to WordPress:
- Updating the WordPress header.php theme file manually (not recommended).
- Using the functionality within your theme (if it has it).
- Using a plugin.
If there’s no provision for you to add Analytics tracking code through a feature in your WordPress theme, the preferred way for most people will be to use a plugin.
That’s it for now.
Share these on Pinterest!
How did you add Google Analytics to WordPress? Drop a comment below if you know of another way.