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:
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