How to Add Google Analytics to WordPress in Three Simple Steps

Love it or hate it, you really should be using Google Analytics on your WordPress site.

Even though the dark overlords at Google have restricted a lot of the data that used to be available in Analytics, it’s still an extremely valuable tool for gathering intelligence on your site visitors. Analytics can show you where they landed, what they read, how long they stayed, what they were searching for, and a heap of other valuable stuff.

You can add Google Analytics to WordPress in 3 easy steps
Google Analytics gives you a closer look at your site’s performance

As a serious WordPress blogger who aspires to greatness, you really can’t afford to be without it. This article shows you how to add Google Analytics to WordPress with minimal fuss and very little effort.

Step One: Get a Google Analytics account

If you haven’t already signed up for analytics, you’ll need to venture over to Google and get hooked up with a free account. Don’t worry, it’s quick and painless.

Once you’ve completed the sign up process, you’ll be given a piece of JavaScript code. It looks like this:

This is the JavaScript code you need to add to your site to use Google Analytics
This code allows Google to gather anonymous data on how your website is being used

Featured Plugin - WordPress Ecommerce Shopping Cart Plugin

Out of all the WordPress ecommerce plugins available, MarketPress has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Step Two: Add the Google Analytics code to your WordPress theme

To do this, you’ll need to open up the footer.php file of your WordPress theme. You can either use an FTP client to access your server, or edit your theme files directly from the WordPress dashboard. Your file editor is located under the ‘Appearance’ tab in the sidebar menu.

This is how you paste your Google Analytics code into your WordPress theme

In the list of template files to the right of the text editor, find footer.php and open it. To add Google Analytics to WordPress, you now just need to copy and paste your code immediately before the closing </body> tag. Like so:

This is how you paste code into your footer.php file

Make sure you save your footer.php file once you’ve pasted in the new code. Google Analytics should now be able to track every page of your WordPress site and provide you with that sweet juicy data.

Step Three: Double check that your analytics is working

To make sure that the script has installed correctly, go back to your Google Analytics home page and click the admin panel in the top right corner of the screen. Open the relevant account, and click the ‘tracking code’ panel. If the Tracking Status is ‘Receiving Data’, then you’ve successfully added Google Analytics to your WordPress site.

Make sure your Google Analytics code has installed properly

Featured Plugin - WordPress Newsletter Plugin

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

Alternatively, use a Google Analytics plugin

If you’re not comfortable hacking around in your WordPress template files, or you want to explore some additional options and functionality, you can also add Google Analytics to WordPress with the use of a plugin. These plugins will typically give you an interface in your WordPress dashboard where you can add the code directly, without having to delve into your theme files.

There are quite a few Google Analytics plugins to choose from, and I wouldn’t necessarily recommend one over the others. Have a look for yourself in the WordPress plugin directory. If you have a multi-site solution, I would also suggest checking out WPMU Dev’s Multisite Google Analytics plugin.

Photo courtesy of Flood.

Comments (25)

  1. That’s bad advice. Don’t edit your theme if you can use a plugin. Switch to a different theme and your analytics will stop working. The themes and plugins editor in WordPress is a recipe for disaster too. There are a bunch of Google Analytics plugins out there, Yoast’s doesn’t ever require you to copy/paste your tracking code, it logs you in with OAuth and asks you to select your Analytics profile, very user friendly. Don’t reinvent the wheel and stop this “without a plugin madness” kthx bye :)

    Related: http://kovshenin.com/2012/plugins-vs-without-a-plugin/

    ~ Konstantin

      • It’s not just a matter of preference. You follow enough of these tutorials and you have random code in your header, footer, functions files and you are bound to miss something important. If it’s something that should work regardless of the theme you are using then it most definitely should be in a plugin. That will save you both time and headaches.

        • Konstantin has a good point. It takes 30 seconds to update the code in your footer/header IF you remember what you did. I don’t want to dread the next WordPress update because I can’t remember how I fixed up my site after reading a tutorial, figuring it out, and pasting in the code.

  2. I’m sorry but I don’t get it……it’s like going through rabbit holes….I don’t have all kinds of time to waste. I cannot find anything you posted here. There is no tag number one. Number two….my wordpress dashboard does not look like that. There is no editor after I click on appearance.

  3. Thank you so much! I hate it when all the info you get to adding something to your blog is “just add the code to the php file…” when I have no idea what they mean half the time! I tried adding the wordpress plugin for this and got a “fatal error” ooh scary, so thank you thank you, it’s working, thank you for the screen caps, that REALLY helps! (Google had said to paste the code “onto every page” you want tracked, which was really not helpful!)

  4. If the code is in the footer, the analytics code is generated when the page fully loads. This has the effect of skewing the bounce rate to the positive. People who leave before the page is fully loaded are not counted as page visits.

    There used to be an advantage in load time by putting the code in the footer. However, since the new code is asyncronous that is no longer the case.

    • hi,

      i’m using wordpress.com not wordpress.org…i know there’s different allowances for what can be done with .com or .org, so any chance you can help me out on how to install google analytics in .com? is it possible?

      thanks x

  5. the yoast Google analytics plugin on my site has not been giving me any new updates for the past 2 days , yet the status on the tracking info tab say “Recieving data”.I am thinking of going manual

Participate