Chances are, if you’ve set up a website with WordPress, it would be really nice to know how many visits you’re getting, where those people are coming from, which posts are the most popular, etc. Google Analytics is a great tool for that job. But how do you use Google Analytics with WordPress?
There are tons of places you can go to learn how to set up a Google Analytics account, so I won’t go into that here. But basically how Google Analytics works is you set up your account, tell it what website you’d like to track, and then Google gives you a bit of code, called a code snippet, that needs to be added to your site to enable Google to track what’s happening on your site and provide you with reports.
Examine your options
Well, you’ve got three basic options for including that code on your WordPress site:
- Choose a WordPress theme that allows you to enter your Google Analytics tracking code in the WordPress admin.
- Copy the code snippet to your footer.php or header.php of your theme.
- Use a plugin to add the snippet for you.
Options 1 and 2 seem pretty sweet, particularly option 1, right? Easy, no fuss, no muss. But I actually don’t recommend that you go with either of those options. Here’s why:
Your Google Analytics tracking and reporting are not tied to the appearance of your website. They have nothing to do with what color your headers are, how your home page is laid out, or where on the page your menus appear. All of those things, dealing with your site’s appearance, are the function of a WordPress theme. Tracking your site’s visitors and performance are not the function of theme.
Use a plugin
Adding additional functionality to WordPress is the domain of plugins. I highly recommend (urge you, beg and plead with you) that you use a plugin for including Google Analytics tracking in your site. That way, you’ll never be in the situation where you decide to either switch themes or redesign your WordPress site from scratch only to discover that the metrics that would tell you if that effort was successful or not were suddenly not available.
I’ve seen it happen many times. Site owner switches themes, or has a new theme built from scratch, or edits and customizes their own theme only to find that Google Analytics has quit working. Switching themes or modifying your theme should never interrupt your tracking and metrics.
So use a plugin. Please. My favorite is Google Analyticator, which not only makes hooking up Google Analytics to my WordPress sites easy and simple, but also provides me with graphs and charts right inside of WordPress that allow me to see my Google Analytics metrics without having to go and log into Google separately.
Just in case I haven’t convinced you yet, when you use a plugin to include Google Analytics on your WordPress site, you additionally get some extra nice options that would be a hassle to code up otherwise. For example, I’m obsessive about looking at my own site to see if I have new comments or to see how many people are visiting my site. I don’t want my own visits to be tracked. Otherwise, I’d have hundreds of views on every post, but they’d just be me, admiring my own work. Google Analyticator makes it easy for me to turn off tracking of any users who are logged in. It also lets me track outbound links to see how many people are clicking on links I’ve included in my posts and also allows me to track downloads of files.
Let themes be themes and plugins be plugins. Use a plugin for adding Google Analytics tracking. That way, the next time you redesign your site, you’ll be sure that your metrics are intact and you’ll know right away if your new theme is helping people read your content or find new content.