How To Setup Google Analytics On WordPress

This post contains affiliate links. Which means I will make a commission at no extra cost to you should you click through and make a purchase. Read the full disclosure here.

So you’ve started a WordPress blog and you’ve begun creating content. But do you know how to setup Google Analytics on WordPress?

Without this crucial tool – how can you tell what blogging strategies are working?

Do you know what your top blog posts are?

Or how many people visited your blog last month, or the month before compared to this one?

Well, unless you’ve got a way to measure these things, like Google Analytics. Chances are you won’t know the answers.

And believe me, it’s important for you to know the answer to these kinds of questions. After all, how else will you be able to tell what works well and what doesn’t?

So here’s what you can do to start collecting that information. So you can use it to improve your blog. Based on actual data coming from your blog and your actual audience.

Google Analytics is the best way to collect and analyze this kind of information on your blog. So today I’m going to show you exactly:-

  • How to get your own Google Analytics account
  • Where to find your WordPress Google Analytics UA ID and script
  • What kinds of information you can get from Google Analytics
  • How to setup Google Analytics on WordPress for your blog using 9 different methods
  • What pros and cons each method has
  • And how to check if Google Analytics on WordPress is working correctly or not

Why Are There So Many Different Methods To Add Google Analytics To WordPress?

You might be wondering. Why 9 different methods?

Well, that’s because everyone’s blog is different. And everyone is comfortable at doing different things. Meaning there should be something for everyone in this list! Even if you don’t get along well with tech.

So, there are options to keep things simple. By only linking your WordPress site to Google Analytics with no extra features. In addition, some options let you install Google Analytics. And also view the stats directly in WordPress itself. Also, I’ve even included a few different methods that do not require any kind of WordPress plugin. In case you want to avoid adding more plugins to your WordPress blog.

In order to use these methods, you’ll need a Google Analytics account which I am going to cover exactly how to get below. You’ll also need your WordPress blog setup and ready to go on your web hosting. So if you haven’t done that yet. Head on over to here to get your blog started and WordPress installed first, before you continue below.

And before we start with how to setup Google Analytics on WordPress. Let’s first understand what Google Analytics are and what they can be used for.

How To Setup Google Analytics On WordPress

What Are Google Analytics?

Google Analytics is a tool that lets you collect lots of different information about your blog and it’s traffic.

This information can be viewed in various different graphs and reports. Which lets you learn about your blog and make data-driven decisions on what to focus on next.

Within the Google Analytics dashboard, there are several areas of information covered.

How To Setup Google Analytics On WordPress Preview Of Dashboard

What Information Can You Find In Google Analytics?

Within the Google Analytics dashboard there are many reports which are grouped into 5 sections. Each section can tell you various different stats about your blog and its visitors. Like this:

Real-TimeLive information about the current visitors that are browsing your blog.
AudienceLearn who your audience is. Shows you general information about the amount of visitors to your blog within certain date ranges. Including information of total visitors, how many of these are new, the number of pages views, bounce rate and duration on the page. Location, devices used, demographics and more.
AcquisitionShows you where your blog traffic is coming from, including whether they come through social media, direct, referrals, search engines and more.
BehaviourContains flowcharts for where visitors land on your blog and which pages they progress to. Page load speeds and event tracking can also be checked here.
ConversionsLet’s you setup goals and money values for certain actions visitors complete on your blog. Once setup you can track goal progress, conversion rates and potential earnings.

How To Use Google Analytics To Improve Your Blogging Strategy

You can use Google Analytics to improve your blogging strategy. As you can use it to find out what content is popular. Since you can track which pages get the most pageviews. You can then use this information to create more content that is related or similar.

This new content is more likely to be popular too. And sometimes it can possibly surpass your previous popular posts in terms of traffic and engagement.

So, rather than you just guessing what is likely to be popular. You can use Google Analytics to make data-driven decisions based on your Google Analytics.

You can also use it to track your overall growth and success. By looking at stats, like traffic and pageviews to see if your blog is growing. You can even compare each week, month or year.

Installing Google Analytics On WordPress You Can Make Data-Driven Decisions

With WordPress Google Analytics you can track where you traffic is coming from. Which you can then use to help you keep doing what is working. And change what isn’t.

For example if you are doing certain tasks for Pinterest for a certain month. And the traffic from Pinterest has shown a significant amount of growth. Then it is likely based on the data. That this strategy might be better than the one used previously, right?

If you are seeing lots of traffic from certain social networks like Facebook but not much from say Twitter. Then either you need to change your strategy for Twitter. Or consider that your audience might not hang out on there much. And that focusing your efforts on Facebook might instead give you better returns on your investment in comparison.

Baring in mind you should always try to diversify your traffic. Especially when it comes to social media. As it is not wise to put all your eggs in one basket. As an issue or change could have a drastic impact on your blog traffic and thus any income too.

All of this is only possible once you know how to setup Google Analytics on WordPress and actually implement it.

For a completel free tool, this is a must-have and must-do asap task for any new beginner blogger!

How To Create A Google Analytics Account

Right, so let’s look at getting a Google Analytics account setup. First, go to the Google Analytics website here.

You will need to use a Gmail account to login. If you don’t have one you will need to set up one first here.

Once signed in, on the next screen, like the below. Click on sign up.

How To Setup Google Analytics On WordPress By Signing Up For Google Analytics Account

Make sure to leave Website selected at the top and not Mobile.

How To Setup Google Analytics On WordPress By Filling In Details For Analytics Account

You should also:-

  • Set an account name
  • Enter a meaningful website name
  • Set your website URL
  • Select a category (optional)

Finally set the Reporting Time Zone to a country and timezone that is appropriate to you. Usually, this will be your country and timezone so the times on the report make sense!

Make sure to set this right as any data collected with the wrong timezone cannot be changed. Changing your timezone later will only update newly collected data going forward.

Getting Your WordPress Google Analytics UA Tracking ID & Script

The next important step is to get the code and scripts you will need to add to your WordPress blog.

So click the Get Tracking ID button.

Then review the following page and if you agree to the Google Analytics terms of service click I agree to continue.

This next screen is extremely important. Make sure to copy down the Tracking-ID, this always starts with UA. And make a copy of the script too, as depending on the method you might need to use that instead.

How To Setup Google Analytics On WordPress With These Codes That Need To Be Added To Your Blog

But, if for any reason you need to find this code again. You can find it within the Google Analytics dashboard by clicking on Admin at the bottom of the menu on the left side of the screen.

Then under the column for Property, click Tracking Info.

Next, below this click Tracking Code. Here your Tracking ID and Website tracking script will be displayed again.

Before Installing Google Analytics On WordPress

Before we start with installing Google Analytics on WordPress though. This is your friendly reminder to backup your blog. If you haven’t got your WordPress backups setup yet. Then follow this guide to get it set up now!

How Long For Google Analytics To Work?

Another common question about how to setup Google Analytics on WordPress. Is how long it takes for the analytics to start working. So it is worth noting that once installed it does take time for the Google Analytics to start working! In general, expect most Google Analytics to be running within 12-24 hours of installing.

How To Setup Google Analytics On WordPress Using a Plugin That Includes Reports

The MonsterInsights Plugin

How To Setup Google Analytics On WordPress Using The WordPress Plugin Monsterinsights


Cost: Free to Premium

This WordPress plugin was formerly known as Google Analytics for WordPress by Yoast. But it is now maintained by WPBeginner.

The first thing you need to do is install the MonsterInsights plugin. If you are not sure how to go about installing plugins then click here. For a complete beginners guide to WordPress plugins.

Once installed, Activate the WordPress plugin.

Now, in the WordPress dashboard on the left side menu, go to Insights > Settings.

Look for the option to Authenticate with your Google account and click on it.

When prompted sign in to the account you set up earlier.

You will be prompted to give MonsterInsights access. Click on Allow if you are happy with this.

You should then select the website you set up earlier for your blog.

Tick the I’m not a robot captcha form.

And then finally click Complete Authentication.

It will then take a while before Google Analytics starts recording your stats. To further customize. You can go through the settings menus to change your preferences.

The Pros Of Using MonsterInsights To Add Google Analytics To WordPress

  • Using this plugin you can view analytics from within your dashboard. By clicking Insights > Reports
  • You don’t have to log into a separate account to view your analytics
  • Also links your website to Google Analytics so it can start tracking.
  • Very easy for beginners to set up
  • No need for copying, pasting or editing any code.

Cons Of Using MonsterInsights For WordPress Google Analytics

  • An extra plugin for something you could do without the need of a plugin as you will see below.
  • Some features are locked behind the Pro version.
  • The Pro version of this plugin is extortionate, so avoid it and only use the free version if it is beneficial to you.

Google Analytics Dashboard for WP

How To Setup Google Analytics On WordPress Using The Plugin Google Analytics Dashboard For Wp By Exactmetrics Formerly Gadwp


Cost: Free to Premium

So, you should be able to easily install this plugin, using Plugins > Add new and searching for the plugin by name there.

Once installed, go to Google Analytics > General Settings from the left side menu. Then from there click Authorize Plugin.

On the next screen, you’ll need to click on Get Access Code and then sign into your Google Analytics account.

Click on Allow and you’ll be given a code that you need to copy.

Take the code and paste it into the plugin screen you were on earlier in the Access Code box.

Make sure you click on the Save Access Code.

Your Google Analytics should now become active on your blog soon.

Also, to exclude yourself from being tracked you can go to Google Analytics > Tracking Code.

Then from the tabs at the top of the page select Exclude Tracking. And select the WordPress user roles you want to be excluded. Usually, this would be Administrator and Editor.

Click Save Changes once set.

Pros Of Using Google Analytics Dashboard for WP Plugin

  • Review basic stats from directly in your WordPress dashboard
  • Additional tracking features
  • Exclude certain WordPress user roles from tracking for more accurate stats

Cons Of Using Google Analytics Dashboard for WP Plugin

  • Reviews suggest it might sometimes lose data depending on your blog setup

How To Setup Google Analytics On WordPress Using a Plugin That Has No Extra Reports

Insert Headers And Footers Plugin

How To Setup Google Analytics On WordPress Using The Insert Headers And Footers WordPress Plugin


Costs: Free

Now, to start with this WordPress plugin. Go and grab the Insert Headers and Footers plugin to install and activate it.

Once installed go to Settings > Insert Headers and Footers.

Copy the Google Analytics script code you would have received earlier. You can then paste it into the Scripts in Header section.

Click Save Changes at the bottom. And done.

Yes, that’s it! It was super simple, right?

Now as previously mentioned, and with all other methods here. It takes some time for Google Analytics to start displaying your traffic. To view your blog analytics though, you will need to log into the Google Analytics website.

Pros Of Using Insert Headers And Footers Plugin

  • Quick and simple to install
  • A free and lightweight plugin that should work with the majority of blogs

Cons Of Using Insert Headers And Footers Plugin

  • No advanced tracking
  • Have to copy and paste the code
  • Have to login to Google Analytics separately to view stats and reports

Analytics Cat

How To Setup Google Analytics On WordPress Using The WordPress Plugin Analytics Cat


Costs: Free

So, firstly go find, install and activate this WordPress plugin. Using Plugins > Add new from the WordPress dashboard left side menu.

Once installed go to Settings > Google Analytics Manager from the dashboard menu

You can skip connecting Google Analytics to the Fatcats Apps by clicking Skip This Step.

Then on the next screen. Enter your Google Analytics ID into the box and leave the Exclude users as the default options. This will stop your own pageviews from being counted.

Click Save once done, and that’s it for this method. Easy, right?

Pros Of Using Analytics Cat

  • Lightweight WordPress plugin
  • Free
  • Ability to exclude users
  • Extremely positive reviews
  • Simple to set up

Cons Of Using Analytics Cat

  • No internal reports on WordPress

Genesis Simple Hooks

How To Setup Google Analytics On WordPress Using The WordPress Plugin For The Genesis Framework Called Genesis Simple Hooks


Costs: Free

If you are using a Theme that uses the Genesis Framework. Then you can also add the Genesis Simple Hooks plugin to your blog. This plugin makes it super easy to add code to not just the header of your blog but also other sections too.

Go ahead and add the plugin to your blog.

Then from Genesis > Simple Hooks look for wp_head Hook.

In the text box paste the Google Analytics script from earlier.

This box can also be used to paste code to install things like:

  • The Facebook Pixel
  • Pinterest Rich Pins
  • Pinterest Pin-It button
  • Google Ads
  • Opt-In email forms like from MailerLite
  • And many more

Basically, anything that asks you to add code to your header. You can use this WordPress plugin for it.

Once you’ve pasted your code make sure to click Save Changes. Then within 12-24 hours you should start seeing stats in your Google Analytics login.

Pros Of Using Genesis Simple Hooks

  • Lightweight plugin
  • Useful for many other codes like Pinterest, MailerLite and Facebook Pixels
  • Simple to use

Cons Of Using Genesis Simple Hooks

  • Requires the Genesis Framework
  • No internal analytics reports so you have to log in separately to view the stats

CAOS – Complete Analytics Optimization Suite

How To Setup Google Analytics On WordPress Using The WordPress Plugin Complete Analytics Optimization Suite Caos


Costs: Free

This plugin helps to set the WordPress Google Analytics UA ID for your blog. But with the added benefit of hosting the analytics file directly on your server. This can boost page load speeds. And remove some pesky errors if you’ve ever done an analysis of your blog on one of the many popular website speed tests.

Firstly, install the WordPress plugin.

Then go to CAOS > Settings.

Enter your Google Analytics UA Tracking ID into the first box.

If you want to use this plugin with the Monster Insights plugin. Which was also included in this list earlier. Then you’ll want to tick the Enable compatibility with Monster Insights?

Click Save your settings.

Pros Of Using The Complete Analytics Optimization Suite (CAOS) Plugin

  • Enables analytics tracking. Which you can either view on the Google Analytics website. Or directly in WordPress using Monster Insights
  • Helps optimize the speed of your blog slightly. By hosting the files required by Google Analytics locally on your server.
  • Simple to install
  • Works with Cookie Consent plugins to help with GDPR settings

Cons Of Using The Complete Analytics Optimization Suite (CAOS) Plugin

  • Requires an additional plugin to view reports directly in WordPress

How To Setup Google Analytics On WordPress Without A Plugin

Sometimes you might want to add Google Analytics to WordPress without a plugin. Either because the Google Analytics WordPress plugins cause conflicts on your blog. Or perhaps you are just trying to keep the number of plugins you use down to a minimum.

Keeping the number of plugins you use on your blog to a minimum. Can be beneficial for your blog’s loading speed. But it does also depend on the optimization of each plugin that you are using. The only way to know for sure is to do several website speed tests both before and after installing a plugin. And taking a close look at the overall average loading speeds for each case.

How To Setup Google Analytics On WordPress Using Your Theme’s Customizer

How To Setup Google Analytics On WordPress Using The Theme Customize And Header Footer Scripts Box


  • A Theme with the Header/Footer scripts option in the customizer
  • Google Analytics UA Script

Costs: Free

So, did you know that depending on your Theme. You can go to Appearance > Customize > Theme Settings > Header/Footer Scripts.

And in the box for Header Scripts paste in the Google Analytics script. If you then click Publish to make the changes live. Then the code should be working after a while.

Pros Of Using Your Theme’s Customizer

  • No plugins required or editing Theme files directly.

Cons Of Using Your Theme’s Customizer

  • The code might be lost when changing Themes
  • Not all Themes might have this option

Using Your Theme Files (Header.php)


  • Google Analytics Script Code

Costs: Free

Okay, to use this method, from the WordPress dashboard go to Appearance > Editor.

On the right side is a list of files, look for one called Theme Header (header.php).

If you cannot find it in the list, perhaps because you are using a Child Theme. Like you might do if your Theme is based on the Genesis Framework. Then you might have to click a link like Genesis at the top of the Theme Files list first.

How To Setup Google Analytics On WordPress Editing Your WordPress Theme Files

Once you’ve found and opened the right file into the editor. Press Ctrl and F on your keyboard to bring up the search bar and type into the box </head>

Press Enter on your keyboard to search for this piece of code.

Then just before this </head> tag paste in your Google Analytics Script code.

Remember to click on Update File once done.

And that’s it, done!

Pros Of Using Your Theme Files

  • Doesn’t require a plugin

Cons Of Using Your Theme Files

  • Requires editing core Theme files which could break your blog
  • Also because it is hardcoded into the header.php file your Google Analytics code could be lost. If you update your Theme or switch to a different Theme altogether
  • The exact location of the header.php varies depending on Themes and frameworks
9 ways on How To Setup Google Analytics On WordPress

How To Setup Google Analytics on WordPress Using Functions.php


  • Google Analytics Script Code

Costs: Free

Another way, that is better than editing the header.php. Is to use the functions.php file instead.

You can find this in the same editor as the header.php (using Appearance > Editor). And looking for the functions.php on the right list of Theme Files.

And at the end of the code before the last } symbol in the functions file. Copy and paste this code:

function ns_google_analytics() { ?>
  <script async src=""></script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'UA-XXXXXXXXX-X');
add_action( 'wp_head', 'ns_google_analytics', 10 );

(Above code source,

Now make sure to change the highlighted UA-XXXXXXXXX-X code to your WordPress Google Analytics UA Tracking ID.

And then click Update file to apply the changes. In awhile your Google Analytics should start showing your stats.

Pros Of Using Functions.php

  • Unlike header.php, this file won’t get accidentally overridden losing your code

Cons Of Using Functions.php

  • Requires editing your Theme files which could break your blog

What To Watch Out For When Learning How To Setup Google Analytics On WordPress

How to setup Google Analytics on WordPress is an important task for any blogger. But it can easily get messed up without you noticing. Which can result in some disappointing and inaccurate blog traffic stats.

You need to watch out for duplicate installs! This is a frequent and common mistake new bloggers make. And this will make every visitor count as two. So, only ever use one of these methods listed above.

Finally, don’t underestimate how easy it is to make this mistake. Since there are so many different ways to add it to your blog. And it can be easy to set the code through a certain method and then forget you’ve done it months or even years down the line.

How To Setup Google Analytics On WordPress For ANY blog

How To Test That Google Analytics Has Been Setup On WordPress Correctly

Once you’ve installed your Google Analytics to WordPress. You should double check that everything is working.

In order to do this, login to your Google Analytics dashboard and go to Admin at the bottom of the left side menu.

In the Property column click on Tracking Info > Tracking Code.

The page with your Google Analytics UA-ID will appear and the script code.

However, what you might not have noticed is the Send test traffic button next to your UA code.

How To Setup Google Analytics On WordPress And Test The Install Works Correct With Test Traffic

Click it and a new window should open to your blog. Minimize it and return to the previous window with your Google Analytics code.

What you should notice within a moment or so. Is the active users should have changed from 0 to 1 provided everything is working. If you have filters set up to not count Administrators. Then make sure you are logged out or turn off the filter temporarily.

And if for any reason you see something like:

2 active users right now (including 2 from test traffic).

Then it is highly likely you’ve accidentally installed the WordPress Google Analytics UA code twice somewhere on your blog. Which you’ll want to fix asap!

Wrapping Up On How To Setup Google Analytics On WordPress For Blogging Beginners

All in all, there should be a method for how to setup Google Analytics on WordPress that fits your individual blog’s need on this list. And whilst there are more methods not included on this list. I’ve specifically tried to cover only the ones that are simple and cover a variety of different situations.

Once you’ve got Google Analytics setup on WordPress, make sure you double check that everything is installed correctly by sending test traffic. Otherwise you could risk your analytics being inaccurate and possibly duplicated.

And finally, remember that it can take several hours before you Google Analytics kicks in for the first time. Most blogs can expect to start seeing their traffic results in 12-24 hours. So be patient!

So which method will you use to add Google Analytics to your blog?

If you found this blog post useful then please consider taking a few seconds to share it to your favorite social media platform!

9 Methods! How To Setup Google Analytics On WordPress

8 thoughts on “How To Setup Google Analytics On WordPress”

  1. Thanks for writing a wonderful article. I have learned some new things about how to set up Google Analytics in the WordPress site. Well written and it’s too clear to understand the concept.

  2. Hey Lisa,
    Thank you for the useful post!
    I was going to setup my google analytics but I saw that it just changed to google analytics 4 instead of universal analytics.
    When I pressed advanced I could choose to use the universal analytics.
    I was wondering which one I should choose?

    1. Hey Thomas,

      Thanks for reminding me! I’ll try to get this updated with the changes that come with Google Analytics 4.

      This is just my opinion – but I would at a *minimum* create a Universal Analytics. I am still currently using it as there are many things still missing in Google Analytics 4.

      The simplest choice I think would be to use the *Advanced Options* to *Create both a Google Analytics 4 and a Universal Analytics property*. This way you’ll only need to add the code to your blog or website once. And you’ll be setup to use both. So you’re ready for any situation going forward.

      Oh and once you get to the Web stream details. The code you’ll want to add to your blog will be under Global Site Tag (gtag.js)

      I hope this helps!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stop these 57 common mistakes from holding back your WordPress blog with this FREE Checklist:TAKE ME TO IT!