How to include empty rows data in Google Analytics Reporting API (V3)?

1.1k Views Asked by At

Today I have added another custom dimension in the google analytics- its new custom dimension (dimension 5)

let gaData: any = {
      'start-date': st_date,
      'end-date': end_date,
      'ids': "a:myviewid", // 
      'metrics': 'ga:pageviews,ga:timeOnPage,ga:sessions',
      'dimensions': "ga:dimension1,ga:dimension5",
      'start-index': 1 + (this.pageNo - 1) * this.pageSize,
      'max-results': this.pageSize
    }

Using Google V3 Get API, after adding query params to the URL the final URL will become as

https://content.googleapis.com/analytics/v3/data/ga?start-date=2021-04-26&end-date=2021-05-26&ids=ga:myviewid&metrics=ga:pageviews,ga:timeOnPage,ga:sessions&dimensions=ga:dimension1,ga:dimension5&start-index=1&max-results=10

As of today, I added a:dimension5 so it's not giving any data. When I remove dimension 5 its giving correct number of users' data.

I have checked include-empty-rows - but in the v3 api its already by default as true - Refer https://developers.google.com/analytics/devguides/reporting/core/v3/reference#includeEmptyRows

So if there is no dimension5 data at least I should get the data, otherwise, there is a huge data loss. Assuming if I add another dimension after 1 year then 1 year data will not come which will be very annoying.

Any suggestion will be of great help. Thanks in advance!

1

There are 1 best solutions below

0
On

You have to add some parameter like this,

include_empty_rows=True

include_empty_rows have default parameter as null, 

For more information, see this page.

https://developers.google.com/resources/api-libraries/documentation/analytics/v3/python/latest/analytics_v3.data.ga.html