Vitalii Korsakov
Vitalii Korsakov

Reputation: 47676

How to read my website user (not google user) tracking id from google analytics tracking code?

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?

Upvotes: 0

Views: 114

Answers (1)

Philip Walton
Philip Walton

Reputation: 30461

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.

Upvotes: 2

Related Questions