25

Is there a way to query results using the Core Reporting API (v3) and filtering those results by the User ID assuming that it is being sent to Google Analytics properly?

I've googled this question a lot and read a whole bunch of articles but I did not find one place that does that. Moreover, the fact that I cannot see the User ID anywhere in the reporting interface makes me doubt that this is even possible. I'm guessing I will have to dome something similar to what is recommended here in order to do it?

UPDATE

Apparently, the purpose of my question is not very clear as highlighted by Eike's comment below. What I want to do is generate a report for a specific user with a specific Id using the client API and then combine those results with information I have about this user in my system's database to do something as per my business requirements.

Community
  • 1
  • 1
Kassem
  • 8,116
  • 17
  • 75
  • 116
  • Filter to what purpose ? If you want to filter individual users then you have to set a custom dimension. If you want to filter for visits where the user id is set simply query the user id view which will only have data for sessions where user id was set. – Eike Pierstorff Jun 24 '14 at 13:44
  • @EikePierstorff thank you for your comment. I've updated my question to make it clearer. – Kassem Jun 24 '14 at 13:54
  • 1
    There is no built-in `User-ID` dimension, [but you can create one](https://stackoverflow.com/questions/48886764/google-analytics-match-userid-with-my-sites-account-id/48904630#48904630). – Max Mar 02 '18 at 08:54

2 Answers2

12

The best place to turn to for such questions is the Dimensions and Metrics Reference. If the dimension you're looking for is not there then you cannot query it or use it in a filter.

The list is really well maintained, so it's not very likely there are as-of-yet undocumented dimensions you could use.

User id is not there.

Eike Pierstorff
  • 31,996
  • 4
  • 43
  • 62
  • 1
    Yeh I've seen this list before and I was wondering why `User ID` is not there, which is what got me here in the first place. Anyway, thanks for the help :) – Kassem Jun 24 '14 at 14:19
  • Sorry, I didn't mean to be a smartarse :-) I just think you cannot use dimensions that are not displayed in the user interface (which I understand from the docs is due to privacy concerns). GA Premium can expose the client id via export to Google Big Query, so there is some chance it would do so for user id, too, but I think with the free version a custom dimension is the easiest way. – Eike Pierstorff Jun 24 '14 at 14:24
  • 13
    Unfortunately "...the userId field is not available as a dimension in reports and can not be exported from Google Analytics" - https://developers.google.com/analytics/devguides/platform/user-id#reporting – El Yobo Jun 03 '15 at 00:34
  • 1
    I guess you should be able to create a custom dimension with your user Id (whatever that can be) and use it in reporting. Note that may well violate google's terms of service (I understand philosophically they only allow anonymous tracking) – Simon Mourier Aug 21 '16 at 10:22
  • 1
    I can confirm that what Simon Mourier is suggesting above is a viable way of dimensioning data by a user id, and quering that data via the Core Reporting API. – Magnus Kragelund Nov 07 '16 at 08:20
  • See https://support.google.com/analytics/answer/2709828?hl=en for info on adding custom dimensions – Martin Serrano Nov 20 '18 at 21:22
  • There is a Dimension called ga:clientId, which is not available dimensions and Metrics references – TheShadow Mar 31 '21 at 13:20
  • @TheShadow, really hard to say if that was the case seven years ago when the answer was written. I tend to think that SO should deprecate answers after a few years in any case, but yes, point taken. – Eike Pierstorff Mar 31 '21 at 14:16
2

Well there is a way now.

The docs says the following steps

  1. Set up User-ID in your account
    1. Agree to the User-ID Policy
    2. Read the User-ID Policy. Under I agree to the User-ID Policy, set the switch to ON. Agreeing to the policy enables the feature in your account.
    3. Click Next Step.

2. Set up User-ID in your tracking code

After you enable User-ID by agreeing to the policy, you must implement User-ID in your tracking code.

To employ User-ID, you must be able to generate your own unique IDs, assign IDs to new users and consistently reassign the same IDs to returning users, and include these IDs in the data you send to Analytics.

In this step, you can see the line of code that you have to add to your Analytics tracking code:

ga('set', 'userId', {{USER_ID}}); // Set the user ID using signed-in user_id.

3. Create a User-ID reporting view

User-ID data can appear only in a dedicated User-ID view.

  1. Click Create.
  2. Enter a Reporting View Name. You might want to include the term "User ID" in the name to help you remember that this is a special User-ID view.
  3. Select a Reporting Time Zone.
  4. Under Show User-ID Reports, set the switch to ON.
  5. Click Create.

Related resources https://support.google.com/analytics/answer/3123666?hl=en

Umar Sid
  • 1,317
  • 1
  • 17
  • 24
  • That's a good point. However, there seems to be no way to pull the User-ID with the Core Reporting API. – Angel Alvarado Mar 01 '18 at 18:38
  • @AngelAlvarado Yes, that feature would be really helpful. – Umar Sid Mar 02 '18 at 07:18
  • 4
    while this answer does explain how to start tracking the userid, it does not reveal how that user id would be used to extract user-specific data via the reporting api – Martin Serrano Nov 20 '18 at 20:52
  • 1
    @MartinSerrano Unfortunately "...the userId field is not available as a dimension in reports and can not be exported from Google Analytics – Umar Sid Nov 22 '18 at 10:10