Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reliably get session id generated by Google Analytics?

Using the latest analytics.js code (as of today) is there a way through their JS API I can get the session id?

like image 759
adam0101 Avatar asked Nov 13 '14 18:11

adam0101


People also ask

Is there a session ID in Google Analytics?

Session ID. Session ID is a random, unique string (GUID) which is scoped to the entire session. This means that all hits of the same session can be queried with the same ID.

How do I find session data in Google Analytics?

Where can I find sessions in Google Analytics? To find out how many sessions your site had in the last 30 days, go to the Audience tab in the left hand column of Google Analytics, then click on Overview, then Sessions.


1 Answers

If you're talking about the client ID, you can get that as follows:

ga(function(tracker) {
  var clientId = tracker.get('clientId');
  console.log(clientId);
});

Here's where that's stated in the documentation:
https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#getting_the_client_id_from_the_cookie

Keep in mind that the client ID is (usually) stored in a cookie, so if the user clears their cookies, they'll be assigned a new client ID that may not match the one you have.

like image 167
Philip Walton Avatar answered Oct 20 '22 00:10

Philip Walton