How to exclude traffic in Google Analytics from Dynamic IP addresses?

后端 未结 9 531
执笔经年
执笔经年 2021-02-05 21:04

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

9条回答
  •  攒了一身酷
    2021-02-05 21:48

    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.
    }
    

提交回复
热议问题