Adding Google Analytics to WordPress

One metric that I know we’re going to need even before I do any analysis is web analytics. Those are the statistics that tell me how many people are coming to the web site, what they’re looking at, where they’re coming from, and so on.

OK, I’ll confess: analysis or not, I want to know those things. Let’s face it, everybody does.

So while I will do some analysis to find out what the best package is going to be, while I get to that point I want something in place, even if it’s just so that I have statistics stretching back to the start of the project.

With that in mind, I went ahead and added Google Analytics to NCPP, because:

  • I know how it works
  • It provides pretty good (and detailed) results
  • It’s free

Adding Google Analytics to a WordPress site is pretty straightforward, and consists of three steps:

  1. Sign up for a Google account (we did this in Signing up for a Gmail account)
  2. Get the tracking code
  3. Add the tracking code to your theme files

Activate your Google Analytics account

To get the tracking code, you’ll first need to activate Google Analytics on your Google Account. Go to the Google Analytics site and click the big Access Analytics button in the upper-right-hand corner.

From there you’ll need to log in to your Google account, then click the Sign Up >> button in the lower-left-hand corner.

You need to speciify site information

Next, add your own information to create your account:

Finally, read and agree to the user agreement.

Now you’re ready to get the tracking code.

Get your Google Analytics tracking code

The first think you need to do is decide what you’re tracking. Your choices are:

  • A single domain: This is going to be the choice for most people; it’s a single domain, with multiple potential subdirectories, such as (in my case) http://nicholaschase.com, http://nicholaschase.com/blog, http;//nicholaschase.com/blog/features.
  • One domain with multiple subdomains: Subdomains are basically the first part of what most people think of a “domain name”. For example, www.nicholaschase.com, blog.nicholaschase.com, and chaos.nicholaschase.com.
  • Multiple top level domains: Top level domains are actually the last part of what people think of as a domain name. For example, www.nicholaschase.com, www.nicholaschase.net, and www.nicholaschase.org.

Because I’m dealing with a blog, and URLs look something like http://nicholaschase.com/2011/01/01/post-title/, I’m going to choose the first option.

Once you’ve done that, you can highlight and copy the actual code from the pane on the right-hand side to your clipboard.

Just to be on the safe side, go ahead and paste the code to a text editor such as Notepad, then click the Save and Finish button.

This is the Google Analytics dashboard, but we won’t have anything to look at until we add the tracking code to the site.

Add the Analytics Tracking Code To Wordpess

Now that you’ve got the tracking code, you need to add it to all of your WordPress pages. Fortunately, WordPress, like most content management systems, uses a “theming” system, which means that a few files are used to populate the entire site. The good thing about that is that we can add the tracking code to the theme and it will be propagated throughout the site.

Chances are you looked through various themes and chose one for your site; WordPress is great about making this easy. Fortunately, it’s also easy to edit the files that make up your theme. To start with, log in to WordPress as an administrator and click Appearance->Editor, then click the Footer link in the right-hand column.

Copy and paste the tracking code into the footer file just above the body close tag (</body>) and click Update File.

Now you’ve added the tracking code to your site, but if you go back to the Analytics dashboard, you’ll see that Google doesn’t recognize it yet.

Unfortunately, there’s not much you can do to speed things up, but sometime in the next 24 hours Google will index your page and find the tracking code, and the icon will turn green:

So now you’re collecting data. In a future post, we’ll talk about what that data actually means.

Leave a Response

You must be logged in to post a comment.