22

I've been working on a support center for my company and we need to track individual users when they login. If possible we would like to track details as well such as pages visited and time spent on the site as well. I'm able to track how many people login to the site using a custom variable, but I am unable to track individual users. Here is the code I've been using to try to grab the individual user id:


$(document).ready( function() {
var welcomeEmail = document.getElementById('welcome_email').innerHTML;

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-30086012-1']);

var welcomeEmail;

if( $('#welcome_email').length > 0 ) {
                //This block of logic makes sure that the welcome_email element actually exists, it will not exist if a user is not logged in yet
                welcomeEmail = document.getElementById('welcome_email').innerHTML;
}

  _gaq.push(['_setCustomVar',1,'UserEmail',welcomeEmail,1]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

What am I missing/doing incorrectly. Appreciate any feedback.

liwp
  • 6,746
  • 1
  • 27
  • 39
Tylertac
  • 223
  • 1
  • 2
  • 5

5 Answers5

36

I would say the privacy policy has changed.

You will not (and will not allow any third party to) use the Service to track, collect or upload any data that personally identifies an individual (such as a name, email address or billing information), or other data which can be reasonably linked to such information by Google.

A UserID will not expose to Google any PII about a visitor, and that seems to be what they're concerned about.

Mark
  • 369
  • 1
  • 3
  • 2
  • Do you have a source for that? A custom variable is just that: 'custom' and should be usable to what I see fit ... – David K. Oct 06 '12 at 11:49
  • It says it is in closed beta.Does anyone know how to do this? – Himmators Jan 22 '14 at 09:54
  • 2
    As of Apr 2014, the Google themselves advocates tracking user ids: https://developers.google.com/analytics/devguides/collection/analyticsjs/user-id – Buttons840 Apr 30 '14 at 21:35
  • To be clear, this is correct as long as your UserId isn't a username, an email address, or some other personally identifiable info. If you use an integer or a Guid you'll be fine. – adam0101 Feb 23 '15 at 14:18
20

Just for the record. Here is a guide by Google on how to accomplish this: https://developers.google.com/analytics/devguides/collection/analyticsjs/user-id?hl=en

IMPORTANT It does require you upgrade your property to the Universal Analytics.

UPDATE 2: As of April 2nd 2014 this feature is out of Beta and widely available.

oamsel
  • 475
  • 3
  • 10
15

That is a violation of Google Analytics terms of service. See number 7 PRIVACY.

7.PRIVACY . You will not (and will not allow any third party to) use the Service to track or collect personally identifiable information of Internet users, nor will You (or will You allow any third party to) associate any data gathered from Your website(s) (or such third parties' website(s)) with any personally identifying information from any source as part of Your use (or such third parties' use) of the Service. You will have and abide by an appropriate privacy policy and will comply with all applicable laws relating to the collection of information from visitors to Your websites. You must post a privacy policy and that policy must provide notice of your use of a cookie that collects anonymous traffic data.

And

While the username or user ID is not directly PII, if it is used to tie to a person from a backend system…that’s a violation of the Terms of Service.

Google Analytics is not the tool to use for this type of tracking. A custom backend solution that is hosted on your own servers is the better way to go.

  • Thanks for the answer. We are using Parature to host our support center and they recommended using Google Analytics to do this sort of thing. I will seek another solution, thank you. – Tylertac Apr 11 '12 at 15:19
  • 8
    Per the below comment, it sounds like this is no longer the case. – yoni Aug 02 '13 at 15:24
  • 5
    This answer is wrong. Google allows this now. So how do you track your users in analytics? – a20 Jun 02 '14 at 05:23
  • 2
    See [Mark's answer](http://stackoverflow.com/a/12356016/1212596) for the current status. – Paul Draper Jul 01 '14 at 17:58
3

This article refers to the new policy. Setting a userID that is setup using the customvariable option in Google Analytics is NOT a breach of their privacy policy.

Parvin Gasimzade
  • 25,180
  • 8
  • 56
  • 83
Ning
  • 39
  • 1
  • 2
    Please provide the information here in order to avoid link rot. – Chris Hasiński Nov 22 '12 at 10:48
  • 2
    I can't find anything in that article that refers to the policy or IDs for users that might be registered on a system, it's talking about creating a unique and anonymous visitor id that isn't tied to a user account. – roryf Jul 22 '13 at 17:10
0

Please note:: allows Google to personally identify << is this meant, if google can't indentify this user is ok with their policy?

You will not upload any data that allows Google to personally identify an individual (such as certain names, Social Security Numbers, email addresses, or any similar data), or data that permanently identifies a particular device (such as a unique device identifier if such an identifier cannot be reset), even in hashed form. If you upload any data that allows Google to personally identify an individual, your Google Analytics account can be terminated, and you may lose your Google Analytics data.

https://developers.google.com/analytics/devguides/collection/protocol/policy