Search code examples
google-analyticsgoogle-analytics-api

How to query API for pageviews per user?


We're collecting usage information for a web app that only a few users have access to. We'd like to collect the number of pageviews and sessions per user, per week, and hour of day. Unfortunately, I cannot seem to find an API dimension that slices by individual user. Is this possible using the API and if so, how?


Solution

  • Google Analytics does not usually gives your per-user result (only exception is the user explorer report, which is not available via the API).

    If you are a Google 360 customer you can use BigQuery, the export schema includes a fullVisitorId (a.k.a. clientId) and sessiondId, so you can slice down to users and user sessions.

    Without BigQuery your best way out is probably to add a unique identifier per user as session scoped custom dimension (e.g. the GA client id), and use that as a key to identify users.

    In addition to that you need to be able to break down per sessions, so create a second session scoped custom dimension and send a random number as value with each hit. Since a session scoped dimension will only store the last value in the session this gives you a unique session identifier per user.

    Obviously this will not work for data that has already been collected. There I think you are out of luck.