google-analyticsgoogle-analytics-apigoogle-reporting-api

Custom Dimensions and Date Ranges with Google Analytics Reporting API v4


My report request includes ga:nthDay and ga:dimension3 dimensions for metrics in a date range, but it isn't returning a row of data for each Day Index.

I suspect this is because my custom dimension isn't matching for each day in the range — but why don't they all return a 0 value for each metric?

For example, since I'm using ga:nthDay, I'll get rows with a Day Index of 0000 and 0002 — but no 0001. These rows will sometimes display 0 value for the metrics, but other times the rows just aren't returned at all.

How do I handle the missing days?


Solution

  • Why don't they all return a 0 value for each metric?

    Because the API only returns data that matches your query and for which at least 1 metric is non-zero.

    How do I handle the missing days?

    Try to set the includeEmptyRows query parameter to True: "If set to false, the response does not include rows if all the retrieved metrics are equal to zero. The default is false which will exclude these rows."

    I know this fixes the issue for standard requests, however this won't work when using custom dimensions as this would mean GA would need to know all possible values of your custom dimensions and reconstruct empty rows for all of them (How could GA know all the possible dimension values? Maybe there are some values which haven't been tracked yet, what if your custom dimension has 30K possible values?...).