Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google analytics API v4 max results

Can someone please help me for Google analytic API V4: how to pass: max-result parameter with this class: Google_Service_AnalyticsReporting I am unable to find relevant function to assign max-result parameter value.

like image 678
AfterEdge Avatar asked Dec 19 '22 07:12

AfterEdge


2 Answers

Based on https://stackoverflow.com/a/38922925/1224827 , the parameter you're looking for is pageSize:

The correct name of the parameter you are looking for is: pageSize. The Reference Docs provide the full API specifications.

def get_report(analytics):
  # Use the Analytics Service Object to query the Analytics Reporting API V4.
  return analytics.reports().batchGet(
      body={
        'reportRequests': [
        {
          'viewId': VIEW_ID,
          'pageSize': 10000,
          'dateRanges': [{'startDate': '2016-04-01', 'endDate': '2016-08-09'}],
          'dimensions': [{'name':'ga:date'},
                    {'name': 'ga:channelGrouping'}],
          'metrics': [{'expression': 'ga:sessions'},
                 {'expression': 'ga:newUsers'},
                 {'expression': 'ga:goal15Completions'},
                 {'expression': 'ga:goal9Completions'},
                 {'expression': 'ga:goal10Completions'}]
        }]
      }
  ).execute()

Note: the API returns a maximum of 100,000 rows per request, no matter how many you ask for (according to the documentation). As you attempted max_results this tells me you are trying to migrate from the Core Reporting API V3, check out the Migration Guide - Pagination documentation to understand how to request the next 100,000 rows.

Stack Overflow extra tip. Include your error responses in your question, as it will likely improve your chances of someone being able to help.

like image 163
Blairg23 Avatar answered Jan 19 '23 00:01

Blairg23


You can use parameter page_size: 10000. Hope this helps.

like image 39
Dapeng114 Avatar answered Jan 19 '23 01:01

Dapeng114