Scott Taylor
Scott Taylor

Reputation: 151

Google Analytics API v4: Multiple date ranges returns only one range in dimensions

I am creating a Google Analytics v4 API call, with two date ranges, two dimensions, and two metrics.

The dimensions are ga:source and ga:date, and the metrics are ga:users and ga:newUsers. When I receive a response, the rows contain data for two date ranges, but the dimensions only include the ga:date value for the first date range. First, below is the data I will pass into the API.

request in pastebin

https://pastebin.com/G5PDWSZ1

Second, is the response I get in return:

response in pastebin

https://pastebin.com/BwD6bztA

Notice in the return that each row contains two dimensions, but two dates with two metrics each. If each dateRow will represent a different set of dates, shouldn't each dateRow contain it's own set of dimensions for that range of dates?

Upvotes: 1

Views: 2300

Answers (1)

yanman1234
yanman1234

Reputation: 1019

Taken from the PHP documentation for Google Analytics:

The request can have a maximum of 2 date ranges. The response will contain a set of metric values for each combination of the dimensions for each date range in the request. So, if there are two date ranges, there will be two set of metric values, one for the original date range and one for the second date range.

So what this means is for each date range you will receive a unique set of metrics, not dimensions. Dimensions can be thought of as categorizing terms, that can group or separate the metric values. Metrics describe the actual data found for time span. This being said, it would make sense that multiple date ranges would return a value for each metric supplied, but not necessarily for each dimension. It is very possible that one date range contained no metric values under a dimension category, as such that dimension will not be shown, since dimensions need a metric value to describe.

Upvotes: 2

Related Questions