Search code examples
google-analyticsgoogle-analytics-apigoogle-analytics-4

How to include the totals field for batchRunReports from GA4?


In GA3(UA), when making a call to their API batchGet endpoint (https://analyticsreporting.googleapis.com/v4/reports:batchGet), in the response it returns a field containing the total of each metric requested so you don't have to iterate through each row.

I am trying to do the same for GA4 but it doesn't return the total field. Has anyone figured this out before? I checked around and a similar question has popped up but it was language specific, so I couldn't apply it. I am creating the request via Postman.

I have tried looking at the GA4 documentation and in the response object(https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/RunReportResponse), it has the totals field and states returned if requested but it does not state how to request this.

GA4 Response (no totals field)

GA3 Response with totals field


Solution

  • Looks like you need to add TOTAL the metricAggregations list in your request, see : https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#:~:text=see%20Pagination.-,metricAggregations,-%5B%5D