swizzard
swizzard

Reputation: 1095

Google Analytics Reporting API V4 Lifetime value requests - invalid dimensions/metrics

I'm trying to make calls the Analytics Reporting API V4 and keep getting back unspecific error messages when trying to use certain dimensions and metrics. For example, I consistently get

{
 "error": {
    "code": 400,
    "message": "Unknown dimension(s): ga:acquisitionTrafficChannel",
    "status": "INVALID_ARGUMENT"
    }
}

when passing ga:acquisitionTrafficChannel, despite it being documented as a valid dimension. Similarly, I get

{
 "error": {
  "code": 400,
  "message": "Selected dimensions and metrics cannot be queried together.",
  "status": "INVALID_ARGUMENT"
 }
}

when passing ga:acquisitionSourceMedium (documented here), even when not passing any metrics whatsoever.

Are the docs out of date? Is there some documentation elsewhere about valid combinations of dimensions and metrics?

Upvotes: 2

Views: 1851

Answers (2)

Zach Gollwitzer
Zach Gollwitzer

Reputation: 2383

I ran into this problem as well. When I was in the Google Analytics Dashboard, I clicked on Acquisition->All Traffic->Channels and was fooled into thinking that I needed to combine the ga:acquisitionMedium dimension and ga:newUsers metric together.

enter image description here

enter image description here

When I clicked on ga:acquisitionMedium, it said that combining it with ga:newUsers was valid, despite the error that you mentioned in your question! In reality, I just needed to combine ga:medium and ga:newUsers together.

I know this is not the exact query that you were doing, but here is an example of how I queried New Users count where the dimension channel equaled "organic" (note that I am forming the JSON request with Javascript and then using JSON.stringify(req) to send it):

var req = {
  reportRequests: [{
    viewId: '<Your Google Analytics view ID>',
    dimensions: [{ name: 'ga:medium' }],
    dimensionFilterClauses: [{
      filters: [{
        dimensionName: 'ga:medium',
        operator: 'EXACT',
        expressions: ['organic']
      }] 
    }],
    dateRanges: [{ startDate: '2019-11-01', endDate: '2019-11-30' }],
    metrics: [{ expression: "ga:newUsers" }]
  }]
};

The above query returns 5,654, which is the same as seen in the "Acquisition" section of Google Analytics.

I definitely think the documentation and error message around this could be improved.

Upvotes: 0

Matt
Matt

Reputation: 5168

All the Lifetime Value reports and thus ga:acquisition... dimensions are only valid for App views not web views.

Secondly the cohort/LTV dimensions can only be queried in within a cohort requests for example:

POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
 "reportRequests": [
  {
   "viewId": "XXXX",
   "dimensions": [
    {
     "name": "ga:cohort"
    },
    {
     "name": "ga:acquisitionTrafficChannel"
    }
   ],
   "metrics": [
    {
     "expression": "ga:cohortSessionsPerUser"
    }
   ],
   "cohortGroup": {
    "cohorts": [
     {
      "name": "cohort 1",
      "type": "FIRST_VISIT_DATE",
      "dateRange": {
       "startDate": "2015-08-01",
       "endDate": "2015-09-01"
      }
     },
     {
      "name": "cohort 2",
      "type": "FIRST_VISIT_DATE",
      "dateRange": {
       "startDate": "2015-07-01",
       "endDate": "2015-08-01"
      }
     }
    ],
    "lifetimeValue": true
   }
  }
 ]
}

The error messages should probably be a bit clearer.

Upvotes: 1

Related Questions