Akaoni
Akaoni

Reputation: 1033

Google Analytics Reporting API - Get Activity with User ID

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.

Upvotes: 5

Views: 3567

Answers (2)

Akaoni
Akaoni

Reputation: 1033

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.

Upvotes: 2

MarkeD
MarkeD

Reputation: 2631

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.

Upvotes: 0

Related Questions