Google Analytics: Exclude Your Own Visits

There are several ways already discussed on the net for excluding one’s own visits from Google Analytics.

A list of those solutions can be found here:

However none of those suggestions really solved the problem for me.

The first solution based on IP addresses works well if you access your website at your home or office. But for a nomad like me, it would be a pain to constantly add new IPs for every website whenever I move from one place to the other.

Another solution is to add a custom cookie that doesn’t expire and that will help identify your browser. It just happens that I often clean my browser cookies, and I would have to frequently check if the cookie is installed. Furthermore if I clean my cookies, I’ll have to re-install the cookies for every websites I want to be excluded from. Not a solution for me again.

I will not further discuss the other solutions in the article above because they have too many drawbacks.

There is however an alternative approach not mentioned in this list that works well for me.
It consists of using HTML5’s localStorage feature. Just like the cookie solution, values stored in localStorage don’t expire. But the advantage over the cookie, is that if you clean your browser’s cookie, the localStorage values remain.

I change the Google Analytics’ script to the following:

    var analytics = true;
    try {
            'localStorage' in window && 
            window['localStorage'] !== null && 
            localStorage["analytics"] == 'no'
        ) {
            analytics = false;
    } catch (e) {}

    if (analytics) {
    } else {
        console.log('Google Analytics has been disabled');

Then I add a web page that will add the localStorage value:

    localStorage["analytics"] = 'no';

Post a Comment