Don’t track your own site visits – with WordPress

14 Oct

When it comes to figuring out what posts are doing well and how your traffic is growing overall, you’ll probably be using an analytics package. Like many, I favour Google Analytics because of the depth of their analysis and customisation options.

However, there’s no simple way to filter out your own visits, especially if you’re a traveller visiting your site from multiple IP addresses. A snippet of WordPress code to the rescue.

How to stop Google Analytics tracking admin visits in WordPress

This method seems to work best when manually editing your theme. I’ve had problems with the “analytics code” section of Woo Themes and other customisable themes.

Load your footer.php in a text editor and add in the following code:

<?php global $userdata;
get_currentuserinfo();
if ($userdata->user_level < 2) {
?>

Replace this line with your Google analytics code

<?php
}
?>

The if statement stops WordPress Administrators (i.e. YOU!) from triggering the analytics code. After you re-upload your footer.php file, you’ll find your traffic drops … but down to a true level. This is good: it helps you see where your audience goes, rather than inflating your favourite spots.

With more accurate analytics data, you can make better choices for your audience and make more money travel blogging.

Also see: Travel blogging and Analytics: What analytics are important for your travel blog.

Why #blog4nz is good for my business

2 Responses to “Don’t track your own site visits – with WordPress”

  1. Griffin Stewart December 4, 2010 at 12:05 pm #

    Great tip Craig. I’ve been trying to figure this out for a while. Thanks for sharing.

    • Craig December 6, 2010 at 6:35 am #

      No worries. It’s none too tricky with a bit of php+WordPress magic :) You can change “2” to other log-in levels, but this will stop admins getting tracked (while other logged-in users will still generate the tracking code).