1
votes

I am using google analytics to tract the data and "userid" tracking is enabled on the site.

ga('set', 'userId', '<user_id>');

I am using Google Analytics API to build custom reports and show it in the application. We can see that the information is being tracked by google analytics and is visible in "user explorer" section.

I was wondering is there a way to get sessions, page visits of a user by passing the userId in a query.

enter image description here

1
The user id dimension is not currently available as part of the standard dimensions and metrics, However you can set a user scoped custom dimension to the same value and get the identical data by querying it, ga:dimensionXX - Matt

1 Answers

2
votes

This parameter is not accessible in any way. Actually, in BigQuery (only for premium users) where this parameter is accessible the Id is Hashed.

What you can do is store this parameter in a custom dimension. Enabling this on the tool and setting this with the clientID. To do this you can use the following line just before of the page view.

ga( 'set' ,'dimension1', ga.getAll()[0].get('clientId'))

With that, you can replicate this. But take care, depending on the who, this information can be Private Information (as Name, email and others). And also this can be a High Cardinality Report, allowing to store only 100k differents values, when you pass the limit the users will be aggrouped in (others).