Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • Google+
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Domains ›
Blocking Google Analytics and Statcounter

Blocking Google Analytics and Statcounter

June 28, 2013 Domains Jesin A 4 Comments

Web analytics software available today are designed with one quote in mind “Information is power”, so they collect a ton of information about you, the Internet user. This includes your location (Country and City), web browser used, referred page, your IP address (Google Analytics doesn’t show this info to webmasters), time on site and a wealth of other information. While there are lots of web analytics software available the two most popular of them are Google Analytics and Statcounter. There are lots of browser plugins and software available to block these but if you use this method you don’t have to install “yet another software” without reading its privacy policy and be worried about it collecting information about you.

While this article tells you how to block Google Analytics and Statcounter you can also use this method to block other web analytics scripts. Also note using these methods will prevent client-side scripts (like Javascript) from tracking you but server-side scripts (like PHP) can still track you.

Windows Users

The user has to be an administrator to do this.

Open Start menu navigate to All Programs > Accessories, right-click notepad and click “Run as administrator“.

Go to File > Open and type the following path in the dialog box that appears

%SystemRoot%\System32\drivers\etc\hosts

Add the following lines to the end of the file on a newline.

127.0.0.1	google-analytics.com
127.0.0.1	www.google-analytics.com
127.0.0.1	ssl.google-analytics.com
127.0.0.1	www.ssl.google-analytics.com
127.0.0.1	statcounter.com
127.0.0.1	www.statcounter.com
127.0.0.1	c.statcounter.com
127.0.0.1	www.c.statcounter.com

Save the file and close notepad. Clear the DNS cache by going to Start > Run, type “cmd” and enter the following command.

ipconfig /flushdns

Even though this step isn’t mandatory it is better to do it.

Linux Users

The user must be root or have sudo permissions to edit this file.

Open the command line (use the shortcut CTRL+ALT+T if on GUI) and enter the following commands, if you’re a non-root user with sudo privileges add the “sudo” keyword.

echo "127.0.0.1	google-analytics.com www.google-analytics.com ssl.google-analytics.com www.ssl.google-analytics.com statcounter.com www.statcounter.com c.statcounter.com www.c.statcounter.com" | sudo tee -a /etc/hosts

Clear the DNS cache by entering the following command

sudo /etc/init.d/dns-clean restart

Enterprises

If you want to block Google analytics and statcounter in your office instead of editing the editing the hosts file on each and every system a DNS zone can be created for these domains in your internal DNS server as below

@	A	127.0.0.1
www	A	127.0.0.1
ssl	A	127.0.0.1
www.ssl	A	127.0.0.1
@	A	127.0.0.1
www	A	127.0.0.1
c	A	127.0.0.1
www.c	A	127.0.0.1

This will ensure privacy in your organization.

What does all this do ?

If you’re the curious type who likes to know what is happening behind the scenes read on.

The purpose of the domain name is to make it easy for humans to remember website names but for computers to access them IP addresses are needed. So each domain name like “google.com”,”yahoo.com”,”websistent.com” is mapped to an IP address. When you type a website name in your browser’s address bar a protocol called DNS “resolves” these domain names to an IP address and it following these steps in priority from top to bottom.

  1. Check the hosts file for a static entry
  2. Check the DNS cache of the operating system
  3. Ask the ISP’s DNS server

If it gets the IP address in step 1 or 2 it doesn’t proceed further.

So what we’re doing here is creating a “static entry” for Google Analytics and Statcounter domain names in the hosts file with a wrong IP address 127.0.0.1 (this is a loopback IP) so that the Javascript code which tracks you doesn’t load at all.

But wait a minute what if a webmaster self-hosts these tracking code, will I be tracked ? No. In this case the code will load but it will NOT be able to send your information to its servers (read Google Analytics or Statcounter).

Have a doubt or having trouble getting this work, drop a comment below and I’ll help you out.

Related posts:

windows category thumbnailSetting up an authoritative DNS in Windows Server 2008 Default ThumbnailSetup Google Apps https iconHow to setup SSL certificates on a free ServerPilot plan Default ThumbnailTypes of DNS Records Default ThumbnailCreate your own email with Windows Live Custom Domains

Tags: dns, linux system files, windows

Comments

  1. Alison says

    July 1, 2013 at 11:38 am

    I was wondering how I would know if it is working? When I go to statcounter I still see myself.
    thanks.

    Reply
    • Jesin says

      July 1, 2013 at 8:52 pm

      Hi Alison,

      If you’ve correctly edited your hosts file you shouldn’t be able to open statcounter’s website. Make sure you’ve added all the URLs specified in this article.
      You can check this by opening the command-line and pinging the following URLs

      ping statcounter.com
      ping c.statcounter.com

      You should get replies from 127.0.0.1

      Reply
  2. Jason Long says

    September 17, 2014 at 7:20 pm

    Thank you very much this worked excellently! I will be doing this on all windows machines I have.

    J.

    Reply
  3. ac says

    August 8, 2015 at 11:34 pm

    hello. i have a statcounter account and i still want to track other’s isp who views my blog (in short i still want to access my statcounter account). but i dont want other people to track me when i view their blog. is this possible even if i do this (your instructions)? i am using windows btw.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.