Tracking and analyzing incoming traffic is crucial for any website, even more so for beginner bloggers. By collecting this data you’ll have a better understanding of what is working for you and what is not. Google Analytics is a great freemium service, which does exactly that. The question is how do you add Google Analytics code to your WordPress blog?

Fear not, I’ll help you out.

In this guide I am going to show you how to add Google Analytics code in a few different ways. Some of them are beginner friendly, some require a little bit more courage and knowledge.

Before we can do that we need one very important thing – a Google Analytics account.

Go to Google Analytics and create a new account. If you already have a Google account you can use that to login.

Get the tracking code

The first step is to acquire a tracking code which you’ll need to install on your website. To do that go to the Admin page and click Create Property.

Google Analytics create a new property

Fill out all the details and you’re already one step closer to getting everything working.

Google Analytics property settings

Once you’re done with that hit the Get Tracking ID button.

You’ll be redirected to the final step which looks like this.

Google Analytics tracking code

Now that we got something to work with let’s talk about all the ways we can add it to our website.

Adding the code manually

Adding the Google Analytics code manually is, in my opinion, the best way to do it. To do that we need to place the code right after the first <head> tag in the header of your WordPress theme.

The downside is if you mess something up you can potentially break your blog completely. And it’ll be difficult to figure out what went wrong, especially if you’re unfamiliar with HTML.

But don’t worry, that’s not going to happen.

First go to the Appearance tab in the admin panel and find Editor.

On the right side of the Editor you’ll find all the files of your theme. Locate a file named header.php and click it.

The header file will always be called header.php no matter which theme you use.

Header.php location inside the WordPress editor

Once you’re in the editing window of header.php locate the first <head> tag. Paste your Google Analytics code right after it like shown in the picture below. Click Update File and you’re done.

How to add Google Analytics to your WordPress blog

The last thing you can do is go to Google Analytics admin panel to check if the code is working. To do that click on Tracking info panel on your property and you’ll be able to see whether your code is working or not.

Here you’ll be able to see your tracking ID and tracking information. In addition, you can even test the code by sending fake traffic to your website. Sometimes the code needs some time to register so it’s recommended to wait a little bit before testing.

If you’re using a caching plugin make sure you clear the cache before testing. Otherwise, the code won’t show up in the cached version of your pages.

Adding the code using plugins

Another way to add Google Analytics to your blog is by using plugins. Some SEO plugins like AIOSEO have built-in Google Analytics support, which means you only need to get your tracking ID and paste it into the appropriate field inside the plugin’s settings.

The tracking ID is located on the same page the tracking code is.

If you’re using something like Yoast SEO, or other SEO plugins which do not have Google Analytics support out of the box, you can add the code using stand-alone plugins like Google Analytics for WordPress, GA Google Analytics, or Google Analytics by WebKinder with integrated self-exclusion feature.

This feature helps avoid tracking your own visits to the website as it does not bring any value. This is quite useful if you’re a developer and visit/refresh your website multiple times every day.

Adding the code using theme settings

Most premium WordPress themes have support for Google Analytics either by having a custom field or by giving you the option to add the tracking code to the header without using the Editor. For example, here’s how to it looks inside the theme I use here called Jevelin.

Google Analytics support inside a WordPress theme

Here I can add the code either by pasting the code inside the JavaScript Code field, or simply by entering my tracking ID. Works either way.

To sum up

Google Analytics is a great freemium software that allows you to track and analyze all incoming traffic to your website. Installing Google Analytics is pretty much mandatory if you’re looking to improve your blog and make it grow faster.

There are multiple ways you can add the tracking code to your blog:

  • Add the code manually right after the <head> tag in the header.php file of your theme.
  • Add the code using WordPress plugins.
  • Add the code in your theme’s settings if your theme has Google Analytics support.

That’s pretty much it.

Do you have any questions regarding this tutorial, or other ways of adding Google Analytics to your blog? Share them below!