Instead of using google analytics User ID feature I want to read User Id which ga.js automatically generates and stores in browser cookies. I want to read this id so I can send it to my server. Is it possible?
-
1I don't think you can read cross-domain cookies. I assume that's what you're trying to do? :)frhd– frhd2015-09-28 08:30:21 +00:00Commented Sep 28, 2015 at 8:30
-
oh, you right. Anyway I prefer API for this to avoid any side effectsVitalii Korsakov– Vitalii Korsakov2015-09-28 08:32:27 +00:00Commented Sep 28, 2015 at 8:32
-
This limitation would not apply to analytics scripts hosted on the same domain. Have you considered something like piwik.org?frhd– frhd2015-09-28 08:35:16 +00:00Commented Sep 28, 2015 at 8:35
-
No. I should do this with Google AnalyticsVitalii Korsakov– Vitalii Korsakov2015-09-28 08:59:52 +00:00Commented Sep 28, 2015 at 8:59
Add a comment
|
1 Answer
You can get the client ID that analytics.js stores in cookies as follows:
ga(function(tracker) {
var clientId = tracker.get('clientId');
});
Here's the page in the documentation that describes how:
https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#getClientId
Note: the clientId is different from the userId
Update:
keep in mind that any time the user clears their cookies, the client ID will change. Do not use it to identify particular users.