5

I can't get User Activity from the Google Analytics Reporting API (v4) using a User ID.

Client ID (in a different, non-User ID view) works, however.

Am I missing something?

--

For Client ID

I go here in my Google Analytics web interface:

https://analytics.google.com/analytics/web/#/report/visitors-user-activity/a45743608w76484324p79062844/_u.date00=20190327&_u.date01=20190402&_r.userId=1142688158.1525244974

I get user activity details as expected: Google Analytics web interface using Client ID

--

I call the following:

POST https://analyticsreporting.googleapis.com/v4/userActivity:search?key={YOUR_API_KEY}

{
  "viewId": "79062844",
  "dateRange": {
     "startDate": "2019-03-27",
     "endDate": "2019-04-02"
  },
   "user": {
     "type": "CLIENT_ID",
     "userId": "1142688158.1525244974"
  }
}

I get the expected response:

{
  "sessions": [
    …
  ],
  "totalRows": 14,
  "sampleRate": 1
}

--

For User ID

I go here in my Google Analytics web interface:

https://analytics.google.com/analytics/web/#/report/visitors-user-activity/a45743608w76484324p185098721/_u.date00=20190327&_u.date01=20190402&_r.userId=Not%20Logged%20In-

I get user activity details as expected: Google Analytics web interface using User ID

--

I call the following:

POST https://analyticsreporting.googleapis.com/v4/userActivity:search?key={YOUR_API_KEY}

{
  "viewId": "185098721",
  "dateRange": {
     "startDate": "2019-03-27",
     "endDate": "2019-04-02"
  },
   "user": {
     "type": "USER_ID",
     "userId": "Not Logged In-"
  }
}

I get an error instead:

{
  "error": {
    "code": 400,
    "message": "USER_ID: Not Logged In- not found.",
    "status": "INVALID_ARGUMENT"
  }
}

--

I have tried different IDs, different dates, changing the type to CLIENT_ID, URL encoding the User ID, and User IDs with no spaces - no joy.

13
  • 1
    Why are you sending an API key this is private data you should be sending an access token. Apr 3, 2019 at 8:02
  • 1
    I've added screenshots for clarity.
    – Akaoni
    Apr 5, 2019 at 1:16
  • 1
    Ok you win that looks weird i sent an email to the team at Google I cant promise you will hear anything here but if i do i will let you know. You might also want to submit a bug report issuetracker.google.com/issues?q=componentid:187400 Apr 5, 2019 at 6:30
  • 1
    They are looking into it Apr 5, 2019 at 14:51
  • 1
    Current option is that the api may not be able to handle userid's with a space. they may update the docs. If i hear anything else i will let you know. I will ping them with your issue Apr 9, 2019 at 6:46

2 Answers 2

2

It seems this is indeed a bug which several others are also experiencing.

This bug can be +1'd and followed here:
https://issuetracker.google.com/issues/130161158

Edit: This has now been fixed.

0

From your URL, you are looking for an ID called Not%20Logged%20In- which is not a valid id. Its probably changing the id when you copy paste the URL.

3
  • Thanks for your response. The documentation says that the User ID can be text of any length: developers.google.com/analytics/devguides/collection/… That said, I have tried User IDs with just hex values (e.g. "55d28a097d822306603eb942") with the same result. To clarify, the URLs work fine, it is the API that isn't returning User Activity when utilising User IDs.
    – Akaoni
    Apr 5, 2019 at 0:58
  • Hmm, ok so its lots of users under this ID? The body of your request looks fine, I suspect its the API not being able to handle the spaces as thats the only thing different from my userId hits, and is unusual I would say. Its URL encoded in the web UI only I guess. Can you try with a normal userId format like "not-logged-in" ?
    – MarkeD
    Apr 5, 2019 at 7:49
  • I have tried with no spaces (or hyphens), but still get the error. E.g. "USER_ID: 55d28a097d822306603eb942 not found."
    – Akaoni
    Apr 9, 2019 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.