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

9

12

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?

Sclerosed answered 10/3, 2014 at 8:45 Comment(1)
I think there is a relatively simple method to exclude your visits. The included link contains all the details to do so => #72751491Shornick
F
23

There are problems with many of the popular answers to this question...

  • Even if you're lucky enough to find an IP range, what if you're working from a coffee shop or hotel?
  • Checking host name eliminates hits from a dev environment, but what if I'm debugging the live site?
  • Editing server configurations is annoying/advanced and multiple domains become complicated.
  • Opt-Out extensions either block hits on all websites or none at all depending on who you ask.

So, I combined several other solutions into something that works for me...

  • It follows me wherever I go
  • It works on a dev environment and on live/public domains
  • It only affects me and the sites that I'm developing
  • It turns on/off with one click
  • It's easy to verify that it is truly not sending any data to analytics
  • It can be used by a whole team of people

I keep a "developer cookie" set on my machine at all times just for the domains that I manage. This cookie has a unique value that is specific to me. Then I simply check for this cookie in my scripts before sending any data to Analytics.

Examples of how I put the code into my pages...

JavaScript

if (window.location.host==="mydomain.com" || window.location.host==="www.mydomain.com") {
   if (document.cookie.indexOf("COOKIENAME=COOKIEVALUE") === -1) {
      // Insert Analytics Code Here
   }
}

PHP

if ($_SERVER['HTTP_HOST']==="mydomain.com" || $_SERVER['HTTP_HOST']==="www.mydomain.com") {
   if (@$_COOKIE["COOKIENAME"] !== "COOKIEVALUE") {
      // Insert Analytics Code Here
   }
}

Verifying that the HOST name equals the domain of my live site ("mydomain.com") ensures that the analytics data will never be sent by ANY visitor while viewing from a test domain such as "localhost" or "beta.mydomain.com". In the examples above, "www.mydomain.com" and "mydomain.com" are the two valid domains where I DO want visits to be recorded.

The live site sends data to analytics as expected UNLESS a developer cookie is found with matching values. If it finds that unique cookie set on my device, then my visit will not count towards my totals in Google Analytics (or whatever other analytics tool I might decide to use one day).

But what happens when my cookies get cleared? How do I keep the "developer cookie" set in the background? I created my own Browser Extension for that... https://chrome.google.com/webstore/detail/lknhpplgahpbindnnocglcjonpahfikn

It works just for the specific domains that you choose. You customize your own unique NAME and VALUE for the cookies in the extension's settings.

This method can easily be used by a team of people as long as they use the same NAME/VALUE pair, so developers, content creators, proofreaders, and anyone else in your organization can all view pages without inflating the statistics.

Feel free to share my solution and use my extension to keep those cookies set.

Favien answered 28/5, 2014 at 14:23 Comment(0)
Q
5

FYI, I thought of another approach using HTML5’s localStorage feature. (The advantage over the cookie is that when you clean your browser’s cookies, localStorage values remain.) I’ve written a blog article about it here: Google Analytics: Exclude your own visits

Quaint answered 19/3, 2015 at 11:57 Comment(1)
This is the best solution, thank you! I created an HTML page to set the localStorage value I wanted, and I loaded the page in each browser installed on my machine. IE and Edge will only store localStorage values if run on an HTTP server (a server running on localhost works), not a plain HTML page. Now I just check if that localStorage value exists on my live site, and if so, it skips the Google Analytics initialization. I would be the only one with that localStorage value.Pardew
I
3

I just had someone ask me this questions and stumbled upon this thread. I found an alternative solution using this Chrome Extension to block yourself from Analytics on sites.

Ilyssa answered 8/7, 2015 at 21:15 Comment(0)
A
1

There are two options.

  1. Check for the IP address you have if they are between some range then you can set a range in the IP address filter. Excluding traffic

  2. Setting cookies

Arwood answered 10/3, 2014 at 17:37 Comment(0)
A
1

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.

Appetite answered 9/7, 2015 at 8:21 Comment(0)
I
1

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.
}
Ignoble answered 7/7, 2017 at 15:1 Comment(2)
This is a really clever solution. I'm not sure why it's not voted higher. There will definitely be performance implications, but you could run this as a cron job and store the results in a database or file to mitigate that. Thanks. :)Roam
At first, this sounded like the best solution to me, but I work with static SSR pages and then I would put my dynamic IP to the page source which is a no-go for me.E
B
0

Better option is to use Google Analytics Opt-Out Browser Plugin found here:

https://tools.google.com/dlpage/gaoptout

Birdt answered 15/11, 2016 at 13:45 Comment(0)
N
0

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.

Nelia answered 23/4, 2017 at 19:21 Comment(0)
M
-2

Why not simple add a filter:

  1. Go to Admin
  2. Select View Profile and create a new view
  3. Click on Filter
  4. Add New Filter
  5. Name it IP Exclusion or whatever
  6. Select the Custom Filter Radio Button
  7. Check Exclude
  8. Select IP Address as Filter Field
  9. In Filter pattern Use Regex to define the range of IP address

For example for IP ranging from 182.73.42.140 to 182.73.42.150 The regex would be:

^182.73.42.(1(4[6-9]|50))$

Here's a screenshot for same

If you have trouble understanding RegEx, you may use this tool to create IP range regex

Margaritamargarite answered 11/8, 2016 at 7:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.