Adding Google Analytics to WordPress

Adding Google Analytics to your WordPress blog enables you to see how many people are actually visiting your site. You can also find out where they came from, what they were searching for, what they read, and how long they stayed. There are tons of options when it comes to analytics software, but Google Analytics is one of the easiest to set up and it does everything I need (my only complaint is the lack of real time stats). Today I’ll walk you through the process of setting it up. All you really have to do is add a small chunk of Javascript to every page that you want Google to track. It is possible to manually add it to your theme, but if you were to switch WordPress themes, your changes would be gone. So I’m going to show you how to use a plugin to add it instead. This way theme changes won’t be an issue.

1. Sign up for Google Analytics

It’s pretty straight forward. You can use an existing Google account to sign up, but it’s not required. Go here to sign up: http://www.google.com/analytics/sign_up.html. At the end of the sign up process, you will get a piece of code. We won’t actually be using all that code, but it’s not a bad idea to save it anyway (it’s not the easiest to find later on if you ever end up needing it).

2. Install a plugin

There are plenty of choices when it comes to WordPress plugins for Google Analytics. I prefer to use Google Analytics for WordPress by Joost de Valk. Not only has this plugin received great reviews, Joost is an active member of the WordPress community. Download the plugin, unzip it, and upload it to your WordPress plugins directory.

3. Configure the plugin

Login to WordPress and go to your Plugins page. Find the plugin you just uploaded and click Activate. Now for the plugin to actually work, it needs to know your UA string. This was buried in the code that Google gave you when you signed up. However, there’s an easier way to find it. While you’re logged into Google Analytics, go to the home page by clicking the Google Analytics logo in the top left corner. The home page will list all the sites that you’re using Google Analytics on (there will just be one at this point if you’re setting up analytics for the first time). Just to the right of your domain name, there will be a number. That’s your UA string. Copy it. You’re almost finished. Now go back to WordPress and go to Plugins>Google Analytics. There will be a warning alerting you that Google Analytics is not active because you haven’t entered your UA string. The UA string goes in the first textbox (it’s labeled Analytics Account ID).  Make sure that the Where should the tracking script be placed? option is set to In the footer. You don’t want the user to have to wait for your analytics script to run before viewing your page, so it’s best to load it in the footer. You can adjust all sorts of other settings if you want, but it isn’t really necessary. Click Update Settings and you should be on your way.

Keep in mind that Google Analytics does not give you real-time statistics, so you might have to wait a day or so before you can check on your traffic.

Posted June 18, 2009 by Alex Mansfield

3 responses to “Adding Google Analytics to WordPress”

  1. Thaifile says:

    Thanks for share great post.

  2. sara says:

    Thanks!!!!

Leave a Reply

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