How to Add Google Analytics to WordPress

One of the most powerful tools you need for your website is ironically supplied by the biggest name out there – Google.  Google Analytics is a free tool that gives you a full insight into what your website visitors are doing when they visit your website.  Google handles two thirds of the traffic online (through the google search engine or Youtube).

Business owners need to know who their audience is to ensure their content appeals to that audience, without this you are sailing blind.  By the end of this post you will know a little about Google Analytics, but more importantly how to add Google Analytics to WordPress.

Let’s get into it…

Why is Google Analytics Really Helpful to Bloggers?

Anyone not using Google Analytics on their blog or website is missing out on so much valuable information. Imagine having a store on the high street, you will know who is interested in your brand or products by those coming into the store and if they buy something you know you are doing something right.  But if you have a website and you are not tracking what your visitors are doing and they are not buying anything – how do you know what you need to change?? That is why you need to know who is visiting your site, what they are doing on your site, when do most visitors visit your site and how they are accessing your website.  That is what Google Analytics gives you:


Analytics will actually break down the demographics of your website visitors, this will help you understand who your audience is


It will also break down what they are actually doing on your website, how long they are spending on your website and are they following your CTA (call to actions).  If the reports show that you have a high bounce rate, it shows that they are not engaged with your content – giving you all the information you need to go away and review your content.


Understanding the trends of your site can help you mobilise your campaigns better.  If Analytics shows most of your visitors are on a specific day or timeframe, make sure you are posting to social media more that time of the day or publish a new post during that period to keep them on your site longer.  This will improve your rankings too.


More and more people are searching online via their smartphones, Google has recently changed its algorithms to focus on mobile first – so understanding the percentage of people searching for your site via mobile is important.  It is also really important your website is mobile friendly.

All of this information is really important when you are starting a blog, understanding what users are thinking of your site (staying on it or leaving it) is key to ensuring you can keep up and ensure your site gets better at keeping people on it to improve your rankings and grow traffic.

How to Sign-up with Google Analytics

Like all of the Google tools available to website owners, you will require a google or Gmail account.

Step 1: Visit the Google Analytics Sign up Page.  If you already have a google or Gmail account, then you can use these details to sign in.

If you do not have one yet, you will be prompted to create an account.

Step 2: Once you have signed in, you will be prompted with a screen like the one below:

This is where you will sign up to a Google Analytics Account.

Step 3: On the next screen, you will be given the choice between a website or a mobile app.  Ensure you select website.

After that you will need to fill in some details.  An account name (it will be the profile name for this website in Google Analytics), Website Name, Website URL, Country and time zone.

Once you have filled in the information, select ‘Get Tracking ID’.  You will see the terms and services agreement for using Google Analytics which you must agree to.

Step 4: Now you will see your Tracking ID (code).  You can copy this tracking code ready to paste into your WordPress website.  We will get into doing that in a moment.

We suggest you leave the browser tab open with your tracking ID detail, just in case you need to go back to it.

Now that we have setup a Google Analytics account, let’s go through adding that tracking ID to your WordPress website.

How to Add Google Analytics to WordPress

There are a couple of ways to add your tracking code to your website, let’s start with adding it to your WordPress theme.

Install Google Analytics in WordPress theme

Please note – changing the code of your website is really for advanced users who are familiar with website code. It is also worth pointing out that it is an unreliable method as it will require you to re-add the code anytime you change your theme or even update your current theme will remove the code.

If this is your first-time adding code to your WordPress website, it might be worth testing it out on a test website first. (Most serious bloggers or affiliate marketers will have a test site).

I will be running through how to add the code to your Header.php

Let’s go through the steps:

  1. Open up your WordPress Dashboard, Select Appearance and choose Editor

  1. On the right-hand side of your screen will be a list of theme files, select header.php

Note, that some themes will warn you against changing the code of a website

All the text you see on the screen, is information related to how your website looks, so we want to make sure we do not delete anything from this text file.  So we want to scroll down until you find atag.  Paste your tracking code in straight after this and save the file.

Reminder – you will need to redo this every time you update or change your theme.  To be honest, I have found it much easier using the All-in-One SEO plugin.

Add Your Tracking Code to the All-in-One SEO Plugin

An easier way to add your google analytics tracking code to your WordPress site is by adding it to the all-in-one SEO plugin.

The All-in-One SEO plugin is a great way of helping the search engines find your website and it allows you to add your tracking ID in the basic settings.  This is a much easier option than adding the tracking code to your theme, as it will not require you to update the code at all.

See the steps below:

If you do not already have the All-in-One SEO plugin, Go to Plugins and select ‘Add New’.  Search for All in One SEO and install the plugin.

In the General Settings on the plugin, scroll down and you will find a box dedicated to Google Settings, including a box to add your tracking ID.  Paste your code into this box and you will never need to re add your tracking code unless you remove the all-in-one seo plugin.

Viewing the Reports on Google Analytics

First things first, let’s look at the report for this website. it is currently a week old and the figures aren’t too bad for a new website:

It shows me I have had 14 visitors in the last 7 days, the bounce rate is a little high but is reducing and they are spending around 2mins 35 on my site.

All of the reports in Google Analytics break this down to the post/page on my website.

The Different Headings all have great features to help you, let’s explore them:

Real Time

Once you get established, the real time feature is awesome as you can track what your visitors are doing whilst they are on the website.  Location, Traffic Sources (how did they get to your website), Content Report, Conversions – Set this up to see how many follow your CTA.


This has a number of great features all aimed at telling you exactly who your audience is, this will change as you establish your website – but it will definitely help you tailor your content to your audience.  If your audience is a younger or older age range than you originally thought, you may change your content to fit.  You find out your audience is more female than male – that can be helpful.  I.e. you have a niche website in male grooming, but more woman are visiting as they want to buy gifts for their partners – this can help you tailor the reviews of the product correctly.

Behaviour reports breakdown what they are doing on your website, do they visit one page and leave, or do they follow any Call to Actions you have or check out other pages?


Where do your readers come from?  This tab allows you to track whether they are finding you via the search engines, social media or referral.  Really useful, social media will be a bigger pull until you are ranking better:

The Conversions Tab is where you set yourself goals for your website and it will track them for you.


Google Analytics is such a powerful tool for your website, whether it be affiliate marketing or not it gives you such an insight into your website and what exactly is happening when someone visits your website and lets you know what you need to change to keep them on your website longer.

Hopefully now you know what benefits Google Analytics has, how to create an account and some information around what you will see when you add it to your website.

If you have any further questions about Google Analytics, the please write them in the comments below and I will come back to as soon as possible with an answer.

4 thoughts on “How to Add Google Analytics to WordPress”

  1. Hi John:

    I’m just now starting to use Google Analytics. Before now, it really didn’t make sense since my site is relatively new and not getting much traffic.

    This is very helpful information for a non-techie like myself.

    Can I add a tracking code if I am using Yoast instead of All in One SEO?

    Anyway, you have explained Google Analytics clearly and simply. Up until now, it seemed confusing.

    Thank you so much!

    • Hi Christopher,

      thanks for your comments and taking the time to check out my post.

      I am glad you found it useful, and yes you can do it for the Yoast plugin.  it is very similar, but this video will explain it a little better.

      How to Install Google Analytics in Yoast

      I am glad you are getting your head around Google Analytics, if you have any further questions do not hesitate to get in touch with me.

      thanks again


  2. Hello,
    Google Analytics is very important for knowing where the traffic in your site is coming from and your most visited pages.
    Your post was really clear, using graphics and also the table of content at the beginning made it easy to understand and follow every step.
    Thank for this guide! It was really helpful!

    • Hey,

      Thanks for taking the time to check out my post and leave your thoughts too!

      Thanks for your feedback on this post, I am glad you found it helpful.  Google Analytics is a key ingredient to any online business – and it is even better that it is free

      Thanks again



Leave a comment

Want to Make Money Online?

Get our Affiliate Marketing BluePrint to Success Guide to Making Money Online

If You’re Serious About Wanting To Make Money, You Need This Guide…