How to exclude traffic in Google Analytics from Dy

2019-03-15 17:07发布

Google's detection of Unusual traffic is nice. But how is it handling Dynamic IP addresses?

For example,I do not have ranges of IPs and my ISP provides Dynamic IP which may change everytime my router reboots and it changes everyday. So here, when I get some IP address I see notification w/o captcha. After several reboots I seem to get an IP which was not blocked!

How to solve this type of issues in Google Analytics. Also I know very well how to exclude traffic from single IP and with ranges of IPs but I do not know how to block internal traffic whose IPs changes everyday?

9条回答
闹够了就滚
2楼-- · 2019-03-15 17:38

Give the Ghostery browser extension a try:
https://www.ghostery.com/

It's easy to define which scripts you want to block per domain. As a bonus, the extension shows which tracking scripts are loaded while you browse the web.

查看更多
对你真心纯属浪费
3楼-- · 2019-03-15 17:46

We had the task to exclude a whole company from Analytics. The internet router got IP renewed circa once a day. Turned out that this router like nearly all common routers nowadays offered some options to enable dynamic IP services. Like noip.com for example.

  • You register at noip.com and choose some static domain name of your choice.
  • Then select that service (noip.com) in your router's dynamic IP options section.
  • Enter your credentials from noip.com.

And what happens now is, that the router everyday automatically pushes its new IP to noip.com, where it gets associated to the domain name you registered before. Now on your page you can dynamically check that domain's IP and if it matches the client's (browser's) IP you exclude the Analytics scripts from being printed to the page.

In my case I was on PHP and something along the lines of the following snippet worked out fine. See gethostbyname().

$print_tracking_scripts = TRUE;

if (gethostbyname('my-unique-name.ddns.net') === $_SERVER['REMOTE_ADDR']) {
  $print_tracking_scripts = FALSE;
}

if ($print_tracking_scripts) {
  // Print or include tracking scripts however you like.
}
查看更多
我想做一个坏孩纸
4楼-- · 2019-03-15 17:47

If you are talking about your own computer/network you have several options:

  • Set up a proxy (Fiddler, or if possible a rule in your router) to block calls to google-analytics.com (the proxy should still return a 200 status code)

  • per Gaurav's answer use the Google extension to block GA (there are versions for all major browsers)

  • set a cookie in the format disable-UA-XXXXXX-X where you replace the X with your property id.

The first two options will block all Google Analytics tracking on any site, the last will only stop tracking the property specified in the cookie value.

All of these are IMO better solutions than conditionally including the analytics library. If you have a call to a method from the GA library somewhere in your code and the library isn't loaded this will result in a javascript error. The methods above will at least load a code stub that captures method calls so there are no calls to undefined functions.

查看更多
登录 后发表回答