Are your Google Analytics stats messed up because you go to your site all the time? Would you like to fix that? Well Google provides a way you could block the traffic from a certain IP address. But if you are checking it from a range of computers then that doesn’t really do you any good. You can block a range but what if you use your laptop all over town and connect into different wireless access points. Or in my case when I go to school I get an new IP every day if not more. So what I decided to do was to defeat it with cookies.
The first step is to create a page that will store a cookie to the computer. For this site I added it into the submission page for these posts. No one else comes here so I shouldn’t have to worry about people accidentally getting the cookie set on their own computer. (A side benefit of having it on a page that I use a bunch is that if I clear my cookies it comes back without me having to think about it.) To create a cookie on a page using php you put this at the top:
<?PHP
setcookie (“analytics”, “no_analytics”);
?>
This sets a cookie with the name analytics and the value no_analytics set to that cookie.
Next, we put an if statement around where we record the analytics (for me this is in the header so it is called on every page.):
<?
if($_COOKIE[“analytics”] != ‘no_analytics’) // if there is a cookie for this site that contains this information then the analytics will not be counted
{
?>
& This If statement will check the cookie and if it exists it will not print out the javascript that sends the information to the Google servers. As long as you have the cookie set in the browsers you use, you will be able to visit the site without being counted. And if you visit from somewhere else – if you want you can hit the page, store the cookie and delete it when you are finished!
Leave a Reply