0

With Google Analytics's Javascript tracker, if someone visits a website with IP #1, and 1 hour later (the same day) with another IP #2 (but in the same browser), does it count for 1 or 2 visitors/users?

If it counts for only 1 visitor, how is this achieved?

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
Basj
  • 41,386
  • 99
  • 383
  • 673
  • It counts as one user but multiple visits. It cookies their browser so it can uniquely track them. It saves a unique id in their browser so they next time they go to the page it identifies them as already visited but it is still another visit to the page. – stuyam Aug 02 '17 at 21:12
  • @stuyam So it doesn't store the successive IPs in cookies, but a unique ID? (provided by server rather than client I guess?). Would you have a few more informations about how it works in an answer (even in pseudo code, just to give the idea: 1. First visit 2. Cookie gets created with ID provided by ..., 3. ... 4. Second visit, 5. ...)? – Basj Aug 02 '17 at 21:15
  • It may look at IP address internally somehow but the ID it generates for the cookie has nothing to do with their IP. If you open the web inspector and go to Application > Cookies there will be one named `_ga` which stands for "Google Analytics" and you will have an ID something like `GA1.2.681517004.1234567890` – stuyam Aug 02 '17 at 21:18
  • @stuyam is the cookie set by the Javascript code only? or by GA's server-side code ? – Basj Aug 02 '17 at 21:20
  • It is set by the javascript. If you want to learn so more about how this stuff works I actually open sources a library called Open Pixel which is basically and open sourced version of the tracking pixel Google Analytics uses. https://github.com/dockwa/openpixel – stuyam Aug 02 '17 at 21:23
  • 1
    The javascript gets all the information about the browser that it can such as screen dimensions, operating system, etc. and it then loads a tiny pixel from Googles servers and puts all those parameters into the url like google.com/pixel.gif?dimentions=1080x900&system=mac etc. so google can track the information. Here is more info on how tracking pixels like this work https://stackoverflow.com/questions/19267742/how-does-invisible-pixel-conversion-tracking-work – stuyam Aug 02 '17 at 21:25
  • 1
    Thanks @stuyam. I think your last comment could be posted as an answer (+ small info about when the cookies are set with ID produced by who?). – Basj Aug 02 '17 at 21:27

2 Answers2

1

Google does not take the IP address into account when identifying users.

IP addresses are often dynamically assigned and can change between visits (or even during a visit - in ancient times AOL had a nasty habit of reassigned IPs during visits), so by themselves they would be not sufficient to recognize a recurring user.

Also there might be legal problems - some jurisdictions (e.g. Germany) consider IP addresses personally identifiable information and require that they are anonymized before data processing takes place.

Some Analytics software (e.g. Piwik) still use the IP address to create a "fingerprint" for a user. FWIW, at the "Analytics Summit" in Hamburg/Germany 2016 Google employee Oliver Borm said that Google does not, and will never do, use fingerprinting ( I don't know if he had actual authority to issue blanket statements on Google's behalf, though).

Instead pageviews are aggregated into sessions, and sessions aggregated into users, by use of a client id. If you use the Javascript tracker the client id generated by the JS code and stored in a cookie named _ga.

One of the reasons Google uses Javascript injection to load the tracking code is that this makes the code run in page context, so it can set first party cookies on your domain. If the cookie was set by the Google server you'd have a third party cookie, which would be blocked by many browsers.

Pageviews with the same clientId within 30 minutes without inactivity (customizable to up to four hours) will be aggregated into a session (sessions also end when the campaign attribution changes, after 500 interaction hits, when they are programmatically terminated by the tracking code, and all sessions end at midnight).

Sessions that are calculated with the same client id are aggregated into the unique user metric.

The _ga cookie that stores the client id has a lifetime of two years, but is updated on each visit (so as long as the users returns within two years cookie lifetime is indefinite for practical purposes). Some of the cookie settings can be customized as documented here. You can also use localstorage as an alternative storing mechanism, or even supply your own client id when you create the tracker (i.e. a value that is created and persisted on your server).

Google does not actually care that much about the format of the clientId, but recommends something along the line of a UUID, since the clientId must be unique per visitor.

Eike Pierstorff
  • 31,996
  • 4
  • 43
  • 62
  • Thanks for this excellent answer. So if I understand well: 1. If a come to www.example.com, then I clear the browser history/cache/cookies, then I come back to the same page with same IP, it will be counted as two users? – Basj Aug 03 '17 at 07:30
  • 1
    If you delete the _ga cookie you will be counted as a new user, independently from the IP address (as long as the site uses the standard tracking code). – Eike Pierstorff Aug 03 '17 at 07:31
  • 2. The client ID is generated by Javascript on the client's computer (rather than sent from server). Then, how to avoid potential collisions (user A and user B have the same ID)? Ok, if the ID is long enough, the risk of collision is 0,0000001%, and this analytics data is not so sensitive if there is a collision once a year. Is that right? – Basj Aug 03 '17 at 07:32
  • I think you underestimate the algorithms that create UUIDs ("For example, the number of random version 4 UUIDs which need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion" as per Wikipedia). Also the collision would need to happen within the same Google Analytics account to create a problem, which makes it even more unlikely. – Eike Pierstorff Aug 03 '17 at 07:36
  • Yes, totally true, the probability is negligible. But I just wanted to be sure to understand what's going on internally. Usually "Unique ID" are provided by server (e.g. SO user account number) when the uniqueness is important, rather than client. Of course here with GA, a collision is not a big deal, so it's ok to generate ID on client. My question was rather a terminology one (can we call Unique ID something not 100% guaranteed unique by server). Thanks for your answer. – Basj Aug 03 '17 at 07:41
1

It counts as one user but multiple visits. It cookies their browser so it can uniquely track them. It saves a unique id in their browser so the next time they go to the page it identifies them as already visited but it is still another visit to the page.

It may look at IP address internally somehow but the ID it generates for the cookie has nothing to do with their IP. If you open the web inspector and go to Application > Cookies there will be one named _ga which stands for "Google Analytics" and you will have an ID something like GA1.2.681517004.1234567890

The javascript gets all the information about the browser that it can such as screen dimensions, operating system, etc. and it then loads a tiny pixel from Googles servers and puts all those parameters into the url like google.com/pixel.gif?dimentions=1080x900&system=mac etc. so google can track the information. Here is more info on how tracking pixels like this work How does invisible pixel conversion tracking work?

If you want to learn so more about how this stuff works I open sources a library called Open Pixel which is basically an open sourced version of the tracking pixel Google Analytics uses. https://github.com/dockwa/openpixel

stuyam
  • 9,561
  • 2
  • 21
  • 40