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.












UNITED STATES và đang sừ dụng không?
0 phản hồi cho “WP Tip: Let Google Analytics exclude your own visits”