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.
- Check the hosts file for a static entry
- Check the DNS cache of the operating system
- 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.
Alison says
I was wondering how I would know if it is working? When I go to statcounter I still see myself.
thanks.
Jesin says
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
Jason Long says
Thank you very much this worked excellently! I will be doing this on all windows machines I have.
J.
ac says
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.