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.
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.
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.
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.
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.
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
Related
I am tracking user events on the front end with google analytics, but I would also like to send back end events and be able to match up events for the same user in google analytics.
It looks like I should be able to pass the uid parameter: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#uid but it looks like I also have to pass the tid parameter https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid .
The docs say that "All collected data is associated by this ID" (the tid).
What should I pass for the tid? Why can't I just pass the uid, if that is supposed to be a mechanism for tying events together?
I would like the backend to pass the uid to the front end (actually a one-way hash of the email), and then refer to the user in google analytics with this uid.
Is this feasible? I'm a bit confused about how to implement this.
Many thanks!
The "tid" - Tracking ID - is the Web Property, i.e. the "slot" in your Analytics account that the data goes to. If you do not send a tracking id the calls will disappear in limbo. You find the tid in your property settings under "Tracking Code". It is a string that starts "UA-" and so is also sometimes referred to as UA-ID).
The User ID will not help you to identify users, at least not by default, since it is not exposed in the Analytics interface (it should really be called the "cross device identification id", since that is what it's for). You need to create a custom dimension and pass the value of the User ID there if you want to identify users. Per TOS you must take care that no third party, including Google, can resolve your User ID (or any other datapoint) into something that identifies a person, altough of course you can use yourself to connect data to other data in your backend system.
Actually there is a proper way. I've implemented this for myself.
There's a Client ID parameter, that should be passed with your requests.
And here's you have two options:
Create this client id manually (by generating UUID) on server-side and pass it to front-end. Then use this value when you create your tracker and also use it for server-side requests.
//creating of a tracker with manually generated client id
ga('create', 'UA-XXXXX-Y', {
'storage': 'none',
'clientId': '76c24efd-ec42-492a-92df-c62cfd4540a3'
});
Of course, you'll need to implement some logic of storing client id in cookie, for example.
You can use client id that is being generated automatically by ga and then send it to the server-side by your method of choice. I've implemented it through cookies:
// Creates a default tracker.
ga('create', 'UA-XXXXX-Y', auto);
// Gets the client ID of the default tracker and logs it.
ga(function(tracker) {
var clientId = tracker.get('clientId');
//setting the cookie with jQuery help
$.cookie("client-id", clientId , { path : "/" });
});
Then on the back-end just access this cookie and use that client id for your requests.
Also some information con be found here: What is the client ID when sending tracking data to google analytics via the measurement protocol?
We need to track conversions that happen on a 3rd party site. The only thing we can place on that site is an image pixel and maybe some JS logic for when to fire it.
I know it is possible to fire a conversion using the Measurement Protocol: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#visitor
Ideally, I'd just give the 3rd party an IMG url and that would be it. The problem is the CID (unique client id).
I can try passing the CID from our site to the 3rd party via URL parameter. However, there are many cases where its not available (e.g., IMG pixcel will be in an email, the goal URL is on printed literature) or the 3rd party is not willing to go through the hassle. Is it best practice to pass this CID in this way?
I can try generating a CID, but I can't find a dead simple way of doing that e.g., var CID = generateCID(). The 3rd party site has its own GA on the page. Can I just take their Google Analytics CID and use it in the image pixel URL?
What the best way to do this? Thank you!
If the 3rd-party site has analytics.js already running then using that client ID is probably best. You can get it by doing the following:
var cid;
ga(function(tracker) {
cid = tracker.get('clientId'));
});
If analytics.js is not running, or if you can't access the ga variable for some reason, you can just generate the client ID randomly. This is approximately what Google does. It's a random 31-bit integer with the current date string appended:
var cid = Math.floor(Math.random() * 0x7FFFFFFF) + "." +
Math.floor(Date.now() / 1000);
Only to complement #Philip Walton excellent answer, Google Analytics expects a random UUID (version 4) as the Client ID, according to the official Documentation.
Client ID
Required for all hit types.
This anonymously identifies a particular user, device, or browser
instance. For the web, this is generally stored as a first-party
cookie with a two-year expiration. For mobile apps, this is randomly
generated for each particular instance of an application install. The
value of this field should be a random UUID (version 4) as described
in http://www.ietf.org/rfc/rfc4122.txt
#broofa provided a simple way to generate a RFC4122-compliant UUID in JavaScript here. Quoting it here for the sake of completeness:
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
I am trying to set up my analytic account and wondering if anyone can help shed some light on what I may be doing wrong. I have 6 e-com sites with products and the shopping cart is on a 7th separate site. Each site has its own unique domain.
I have a property set for each domain and then one additional property that is set as a global account. The theory was to track for each separate property and then additionally in the global account. This might be overkill since I am not overly concerned with traffic on the individual sites. But what I am having trouble with is I am paying for adwords so the ad lands on a shopping1.com and checks out on shopping7.com its not registering as a conersion since there is a switch in the domain name.
Here is the code that I, any input on how to make all 7 sites work as one and adwords realizing there was a conversion would be greatly appreciated. Do I need to set the domanname element? Also, do I need to add code to everything that links back and forth to each of the separate sites?
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-site1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
_gaq.push(['global._setAccount', 'UA-global']);
_gaq.push(['global._setAllowLinker', true]);
_gaq.push(['global._trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
The code is okay, but not sufficient. First yes, you should use _setDomainName (with the value set to the respective domain names shopping1.com, shopping2.com etc).
More importantly you need to attach the linker functions to links, forms and iframes (and redirects, although with redirects you need to do the linking yourself) - basically every place where people change from one of your domains to another (it's not necessary to attach linker function to links that do not go to your domains).
Google Analytics uses cookies to store data, which cannot be shared between domains. The purpose of the linker function is to attach session information to the url so it is transmitted to the other domain, where it is read by the Google script and stored into a new cookie. Take a look at the documentation to see how the _link and linkByPost-functions are used.
If you are doing redirects you need to be careful that the redirect keeps the Google parameters.
Linker functions result in very long and ugly urls. Cross domain tracking works much better with Universal Analytics where you only have to transmit a single parameter (the client id) between domains.
I am new to GA and I have the following scenario:
I have a website that does not require the GA services at all except for one page.
This page's URL something like this: http://example.com/events?eventId=1234
What I try to achieve is to count the visitors for the different events specified in the parameter. (So later I can retrieve this information and I can show how many people visited a particular event's site).
I have been looking at https://www.google.com/analytics for a while however I could not figure out how to make the GA distinguish by the parameters. So far I registered at GA and I have the unique code and I can include this to the page:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxxx-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);
})();
Additionally this web application is implemented with Play framework
You can use event tracking or just log a virtual pageview
e.g.
_gaq.push(['_trackPageview', '/events/{id}']);
Replace the {id} with the actual id
By default, the on-page GA code snippet will record the URL, minus protocol and domain. That means if you have
www.example.com/events?eventId=1234
vs.
www.example.com/events?eventId=4567
You will see 2 separate entries in your pages reports:
/events?eventId=1234
/events?eventId=4567
So out-of-the-box you should be good to go.
However...one issue you brought up in a comment:
does it work even if there are other parameters as well?
Yes it will, and that presents a problem. Because these 2 will also count as 2 separate entries:
www.example.com/events?eventId=123&a=b
www.example.com/events?eventId=123&a=c
In order to get around this, you will need to as tszming mentioned in his answer: track with a custom event (or custom variable), or else override the default page name with something of your choice. Or you can do both; each method is basically a different way of looking at the same basic data, and allows you to do slightly different things. But for answering your basic question of "how many people went to {eventId} version of the page, all of the options will answer that.
sidenote: in any case, all of these solutions involve getting a query string param. GA does not have a built in method for grabbing a query string parameter value, so you will have to grab that value yourself. Unfortunately, javascript does not have a built in way of doing it either. Fortunately, it's pretty easy to write a function that will do it for you (just google "javascript get query param").
last friday we switched our website, www.ourweb.com tracking from "single domain" to "one domain to multiple sub-domains", to track both www.ourweb.com and blog.ourweb.com
so i modified the code on the site:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1594022-3");
pageTracker._trackPageview();
</script>
to (note we used traditional snippet before):
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', '.ourweb.com']);
_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);
})();
but over last few days, site reported almost double returning visitors drop! from stable 7 000 down to 4 000
only returning visitors number changed that much, new visitors number keeps being similar (around 10 000)
i read this http://www.roirevolution.com/blog/2011/01/google_analytics_subdomain_tracking.php
and they write there that "The leading period causes cookie resets.". is that the reason of such big visitors drop? should i remove the leading period? and if not, what else could be the reason?
ps. i just noticed that probably it's referrals only problem. amount of visitors from referrals decreased from 4000 to around 700 per day after change.
This is a silly quirk of Google Analytics that should be better documented.
There are 2 equally valid but slightly sifferent methods for using _setDomainName.
No Leading Period:
_gaq.push(['_setDomainName', 'ourweb.com']);
Leading Period:
_gaq.push(['_setDomainName', '.ourweb.com']);
Google Analytics uses something called a "domain hash" (literally, a hash of the domain or of the domain you set in _setDomainName) to prevent conflicts between cookies; if the domain hash of the domain you've configured does not match the Google Analytics cookies that it finds, it creates a brand new visit (and a brand new visitor).
The difference is this: By default, if you don't configure your setDomainName, your root www domain gets a "domain hash" that is the same as if it is just http://ourweb.com. That's presumably to prevent self-referrals for traffic between www. and no www.
However, if you add the leading period, the "domain hash" changes. None of your returning visitors will have a matching domain hash. So, when they enter your site, Google Analytics doesn't see a matching set of cookies with the correct domain hash and creates a new visitor id, and all your traffic since the change is totally cut off from the traffic before the change.
As a result, if you have long-standing tracking without using _setDomainName, and you'd like to add support for tracking across subdomains, the way to do so with the last damage is to use no leading period.
You can "recover" the old cookies by switching to using no leading period. If you do so, you'll lose the cookies since you've made the change, though.
The only benefit in using the leading period is that it provides compatibility for third level subdomains (ie, foo.bar.example.com).
visitors drop happened because there was no straight redirect between ourweb.com and www.ourweb.com
ourweb.com was displaying same site as www.ourweb.com, but with all links pointing to www.ourweb.com, and all 3000 return visits drop came from self referrals.
thus cookies were split between those two sites and created fake unique return visits (each time visitor visited ourweb.com and clicked f.ex. link to about.html, he was going to www.ourweb.com/about.html, so ga counted it as two independent unique return visits)
so basically reporting was wrong before and became more accurate.