KevinHu
KevinHu

Reputation: 1031

Google Analytics api query result missing dates?

I want to use google analytic's query api to build the last week line chart.

dimensions: ga:date

sort: ga:date

but I found the result is missing some date: ex: (1/1 ~ 1/6, should have 7 day's data)

there are only have 1/1, 1/2, 1/5, 1/6 (lack of 1/3, 1/4..)

how to fill the missing data?

I found there is some infomation: https://developers.google.com/analytics/solutions/articles/backfill_dates#backfil

but its java version. Is there any solution for client side?

Thanks.

Upvotes: 2

Views: 509

Answers (1)

Max
Max

Reputation: 13334

Indeed, by default Google Analytics won't return rows if associated metrics are equal to 0 (e.g. if you have a website with low or hit-miss traffic, and you query for traffic on daily basis, you will see those gaps).

The v4 reporting API has the includeEmptyRows parameter (by default set to false) which should prevent this behaviour:

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.

As for filling those gaps with a client-side loop, just identify the missing dates, generate empty rows for those missing dates, and merge the 2 datasets.

Upvotes: 2

Related Questions