How to Add Google Analytics Tracking to WordPress For Beginners

Published on August 2nd, 2017

Last Updated on June 5th, 2019

Tags: ,

Share This Article

Struggling with how to add the Google Analytics tracking code to WordPress? Google Analytics provides you with all kinds of helpful insights about your site…but getting it up and running can definitely be a bit confusing.

Don’t worry – I’m here to help. In this post, I’ll give you four different ways to install the Google Analytics tracking code on your WordPress site. Because you only need one method, I’ll also tell you some of the pros and cons of each method so that you can pick the one that’s right for you.

Let’s dive in!

Where to Find Your Google Analytics Tracking Code

No matter which method you choose to add Google Analytics to your WordPress site, you’re going to need one basic piece of information:

Your tracking code, which also includes your Tracking ID. Some tools require the whole code, while others just need your ID.

You can find this information inside your Google Analytics account. If you haven’t already signed up for Google Analytics, you can do that here. Just click Sign In in the top right and follow the instructions.

Once you do that, Google should show you your tracking information. Or, if you already have a Google Analytics account, you can always find your site’s tracking information by going to Admin → Tracking Info → Tracking Code:

add google analytics to wordpress

As I mentioned, your tracking information contains two parts:

  • The Tracking ID
  • The Website tracking code

Article Continues Below

Keep this information handy as you’ll use it in the following steps to get up and running with Google Analytics.

1. Add Google Analytics to WordPress Manually

I’m going to start with the most lightweight method – manually adding the Google Analytics tracking code to your site’s header.php file. While it’s the simplest functionality wise, it’s also the most confusing sometimes. So if you feel a bit uneasy doing this yourself, I’ll give you some more beginner-friendly methods in the next few sections.

To add the Google Analytics code manually, all you need to do is grab the full Website tracking code and add it to your theme’s header.php file.

To edit your header.php file, you can head to Appearance → Editor and select Theme Header. Then, look for the </head> tag and paste the tracking code immediately before that tag:

Make sure to save your changes by clicking Update File and that’s it!

2. Add Google Analytics with Insert Headers and Footers

The manual method is easy, but it suffers from one flaw – if you ever change themes, you’ll need to remember to add the Google Analytics tracking code again.

To avoid that, you can use a plugin that lets you add the code to your theme’s header. While the end result is the same, the plugin works independently of your theme, so you’ll be able to switch themes without needing to keep adding the tracking code again and again.

To get started, install and activate the free Insert Headers and Footers plugin.

Then, head to Settings → Insert Headers and Footers. Paste your full Google Analytics tracking code into the Scripts in Header box and click Save:

Article Continues Below

And that’s it! Your tracking code is active.

3. Add Google Analytics with Analytics Cat

Both the above methods are totally fine to use. But if you want to get a little more creative, you can use a dedicated Google Analytics plugin.

Why would you want to use such a plugin?

First off – like Insert Headers and Footers, it will work independently of your theme.

But there’s also another benefit – such plugins let you exclude yourself from tracking. Because you’re likely to be active on your site, you really don’t want to pollute your Google Analytics tracking data with your own actions.

For this use, I recommend a simple plugin called Analytics Cat.

To use it, install and activate the plugin, then head to Settings → Google Analytics Manager.

Add just your Tracking ID, not the full tracking code. Then select the WordPress user roles that you wish to exclude from tracking (the defaults are totally fine) and click Save:

Article Continues Below

And that’s it! Your tracking is all set up. Users who fit the excluded user roles will be excluded from tracking, but Google Analytics will show stats for all of your other visitors.

4. Add AND View Google Analytics Charts in Your WordPress Dashboard

By default, the only place that you can view your Google Analytics stats is inside the Google Analytics website dashboard.

If you just want basic stats about your site, though, there are actually plugins that allow you to view your stats inside your WordPress dashboard. While you don’t have to use such plugins, they do make it a bit easier for you to quickly find information about your site.

They’re also more user friendly because you don’t have to deal with learning Google Analytics’ interface.

There are several popular plugins that offer this functionality, but I like Google Analytics Dashboard for WP because it’s 100% free.

To use the plugin, get started by installing and activating it through your WordPress dashboard.

Because the plugin goes beyond merely adding the Google Analytics tracking code, you’ll need to grant it special access to your Google Analytics account. This is necessary for the plugin to actually display data from Google Analytics inside your WordPress dashboard.

To do that, go to Google Analytics and click Authorize Plugin:

Follow the instructions to authorize your account.

Once you authorize your account, you can go to Google Analytics → Tracking Code to further configure how your tracking code works.

Then, you’ll be able to view reports directly inside your WordPress dashboard.

Other options to accomplish the same thing include the free Google Analyticator plugin and a plugin called Analytify.

How to Add Google Analytics Event Tracking to WordPress

Finally, I want to round things out with a slightly more advanced topic:

Google Analytics Event Tracking.

This is not a requirement to add the basic Google Analytics tracking code to WordPress.

Event Tracking is just a feature that can unlock even more insights from Google Analytics.

Rather than rehashing information on Google Events, I’ll just direct you to two posts that I’ve previously written on the subject:

Wrapping Things Up

If you just want the simplest way to add Google Analytics to WordPress, I’m always a fan of doing it manually.

For plugin options that are still simple, Analytics Cat and Insert Headers and Footers are both still good options.

And if you want to go even further, you can use plugins to add event tracking and in-dashboard reports. You can even display your Google Analytics data to the public if you want.

Finally – for even more data, you can also add Facebook Pixel to WordPress.

Now over to you – of the myriad number of ways to install Google Analytics in WordPress, which is your favorite?

Colin Newcomer is a freelance writer and long-time Internet marketer. He specializes in digital marketing, WordPress and B2B writing. He lives a life of danger, riding a scooter through the chaos of Hanoi. You can also follow his travel blog.