Reputation: 214957
I am very new to google analytics. And I am trying to collect some data for my website. What I would like to do is retrieve the session or user id for each page view of my website so that I can group the page views by sessions or users. I have looked through the google analytics documentation and did a lot of search, from where I know that the session and user id are stored in specific cookies named _utm(a,b,c)
. What I don't know is how I get those ids for each of my page view through analytics API preferably. Does anybody have any experience of this? Any help is much appreciated!
Upvotes: 1
Views: 5854
Reputation: 32760
The free version of Google Analytics does not expose client id or user id by default for export (with GA 360 you could use them in a BigQuery export), although you can see them in the new User Explorer Report.
If you want to get them via the API you have to store them in custom dimensions.
The current version of Google Analytics does not the utm cookies anymore, it uses a single cookie that's named "_ga" by default; it contains the client id (what you called session id).
Google offers a method to extract the clientid from the cookie via javascript. Then you'd have to send the value as a custom dimension to Google Analytics, and (After some due processing time) you could extract them via the API; you'd need to specify the dimension by using it's numeric index (basically the order in which the dimensions have been created in the backend).
With the Userid it's somewhat simpler, since this has to be generated by your backend in any case. So you can pass the value you use for userid into another custom dimension, it will be passed on the reporting engine and you can get it from there via the API:
ga('set', 'dimension2', myVarWithaUserID);
Upvotes: 3