The code i'm using is given below , the problem is this is returning only maximum of 1000 rows. What should i add in this code in order to get the whole data?
def get_report(analytics):
"""Queries the Analytics Reporting API V4.
Args:
analytics: An authorized Analytics Reporting API V4 service object.
Returns:
The Analytics Reporting API V4 response.
"""
return analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': start , 'endDate': end }],
'metrics': [{'expression': 'ga:totalEvents'}],
'dimensions': [{ 'name': 'ga:eventLabel' }],
'filtersExpression': 'ga:eventLabel=~C_NOTI_TRAIL*'
}]
}
).execute()
Core Reporting API provides paging fields in a response object so you can access the next report page based on response token https://developers.google.com/analytics/devguides/reporting/core/v4/basics#pagination
Also if you're sure that your report wouldn't exceed 10 000 rows you may manually set the limit value with your request with pageSize filed:
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'pageSize': 10000,
'dateRanges': [{'startDate': start , 'endDate': end }],
'metrics': [{'expression': 'ga:totalEvents'}],
'dimensions': [{ 'name': 'ga:eventLabel' }],
...
}
Make sure to check the description of pageSize
and pageToken
in the docs: https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet#ReportRequest