0

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?

4
  • 1
    I don't think you can read cross-domain cookies. I assume that's what you're trying to do? :) Commented Sep 28, 2015 at 8:30
  • oh, you right. Anyway I prefer API for this to avoid any side effects Commented 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? Commented Sep 28, 2015 at 8:35
  • No. I should do this with Google Analytics Commented Sep 28, 2015 at 8:59

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.