Posted on December 4th, 2008 in WP Tips-Tricks | 1,767 views

After reading the article “Exclude your own visits in Google Analytics for WordPress blogs” on JohnTP.com,
I think that is very useful trick to exclude your own visits in Google Analytics when you access your WordPress blogs, using the code bellow to do that:

<?php if (!$user_ID) { ?> your Google Analytics code here <?php } ?>

But the code is not pretty well for blogs with enabled user registration because using $user_ID variable will exclude all visitors who has already been a member. You know that we are going to exclude tracking for only the administrator whose username is "admin" and level is 10 so that we need to have a better condition to detect which type of currently logged in user. I have an improvement for the code here, place it to your footer.php :

1
2
3
4
<?php global $current_user; get_currentuserinfo();
if ($current_user->user_level != 10 && $current_user->user_login != 'admin') { ?>
your Google Analytics code here
<?php } ?>

This code is currently working well on my blog. I hope it will help you to exclude your own visits in Google Analytics exactly!

PS: Note that you can use any web statistics code you like (statcounter for example), not just for Google Analytics.

Sign up for News and Updates!
digg delicious stumbleupon technorati Google live facebook Sphinn Mixx newsvine reddit yahoomyweb

0 Responses to “WP Tip: Let Google Analytics exclude your own visits”

  1. There are no comments posted yet. Be the first one!

Leave a Reply

Comment moderation is currently enabled so comments with spammy words or a few links might be delayed. Please do not submit your comments twice, they will be approved soon.
Off Auto TELEX VNI VIQR VIQR*