Josh Schumacher: A PHP Developer

The biggest and the best in the Northwest

Josh Schumacher: A PHP Developer random header image

Howto: Exclude developer hits in Analytics

March 16th, 2007 · No Comments

When developing a site, I visit it a lot – OK Josh, that was an obvious. Point is, I was tired of tracking my visits to sites that I maintain. I really care about tracking significant users and how they navigate the site and what pages they find valuable but I don’t care about my hits.

I put together a quick page that I can navigate to that will install a cookie for the browser. I can then check for the cookie in my standard header include so the Google Analytics tracking code isn’t sent to the browser.

The code to set the cookie (and make sure it’s installed correctly)

  1. setcookie("hideAnalytics", 'true', time()+(3600*24*365*30));
  3. if(isset($_COOKIE['hideAnalytics']) && $_COOKIE['hideAnalytics'] == 'true')
  4. {
  5.     print "Cookie installed";
  6. }

Similar (but inverse) code is then inserted in my header

  1. <? if(!isset($_COOKIE&#91;'hideAnalytics']) || $_COOKIE['hideAnalytics'] != 'true') { ?>
  3. <? } ?>

Analytics is a great tool and it’s going to be even more useful now that I won’t be tracking my own hits.

Tags: Analytics · Javascript · PHP

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment