How to prevent google analytics from getting traffic from localhost?

google-analytics, javascript

Solution

Thats quit simple.

you have the possibility to filter it in analytics, but this option jungle in analytics is a bit confusing in my opinion.

you can just do it in your javascript:

if (window.location.hostname != 'localhost' && window.location.hostname != '127.0.0.1') {
    //put your analytics here    
}

Problem

I have an issue. I use google analytics in a small project, and I develop on localhost. Of course I call my site again and again on my local machine, but this pullutes my analytics stats. What can I do?

Original source