Home  |   Blog  |   SEO  |   About  |   éàéø áø-àåï  |  

Disable Google Analytics

I’m using Google analytics quite a lot on every site I work on. Recently we had a problem at one of my customers sites, where the marketing people working in that company were browsing their website all day, searching in Google their website keywords again and again, and made Google Analytics reports become unreliable. There were so many visits in the reports that were not real customers but our own staff, that we didn’t really know which part of the report was real and which part was our own tracks.

Like in every crime scene, we just needed our guys to put on gloves before touching everything…

The solution was very simple.

1. We created a file called disable_analytcis.php

<?php
SetCookie(”disable_analytics”,”1″ ,time()+91536000,”/”);
echo “Yuhu!, Google analytics is disabled!”;
?>

2. In the site footer, next to the Google analytics code, we added this:

<?
if (!empty($_COOKIE[’disable_analytics’]))
{
echo “Google analytics is disabled”;
}
else
{
?>
//put google analytics code here…
<?
}
?>

That was easy. The hard part was to send the link to disable_analytics.php to all the sales and marketing in that company and ask them to click on the link. They ALL wanted to know exactly WTF is going on here… are we spying on them? yes? no? what do you mean Google keeps track??? anonymous? who authorized this… :)

Once everybody got their cookie, our statistics cleared up. Real client analytics emerged and logs turned useful again. When you do it on your site, make sure your cookie gets to all computers, home computers, laptops and any computer that you don’t want to track.

update: (Thanks Pieter!)
Google offers cookie based filters, as described in Google Analytics Help Center:
Create an Exclude filter to remove data from visitors with this cookie. Follow these instructions to create a filter with the following settings:
Filter Type: Custom filter > Exclude
Filter Field: User Defined
Filter Pattern: disable_analytics
Case Sensitive: No

DiggRedditSlashdotTwitThisSphinnStumbleUpondel.icio.usFacebookGoogleTechnoratiE-mail this story to a friend!

5 Responses to “Disable Google Analytics”

  1. Pieter Says:

    As far as I know, Google actually encourage you to set up ‘Filters’ to exclude certain users, departments, etc. See http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55481

  2. yair Says:

    Hi Pieter,
    You’re right!.
    Google suggests to add a separate page that creates the cookie, the same as I did. (They do it with javascript, I do it with PHP)
    The option I didn’t know is cookie based filters.
    I actually like it better, it is less code changes on site.
    I will update my post with this info.
    Thanks!

  3. Al Says:

    this post was very helpfull.
    It is actually simpler then I thouht.
    I was actually trying to disable google analytics by blocking their script through adblock but this looks much easier to my team.
    Thanks!

  4. CMS Says:

    My clients are running on windows servers, do you have code other then the PHP?

    Many thanks,
    CMS

  5. Warner Carter Says:

    clever solution

Leave a Reply




Vulnerability Scanner