Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP & Analytics API - Get 10 rows

I am using Google Analytics Core Reporting V4

With the following code I'm setting up a request for google analytics.

// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($this->sViewId);
$request->setDateRanges($dateRange);
$request->setMetrics(array($pageViews));
$request->setDimensions(array($city));
$request->setOrderBys($order);

How can I tell the request to only get the 10 highest cities and ignore the rest.

like image 786
Nick Avatar asked Aug 04 '26 10:08

Nick


1 Answers

From the documentation it seems that the Report Request has a pageSize property:

Page size is for paging and specifies the maximum number of returned rows. Page size should be >= 0. A query returns the default of 1,000 rows. The Analytics Core Reporting API returns a maximum of 10,000 rows per request, no matter how many you ask for. It can also return fewer rows than requested, if there aren't as many dimension segments as you expect. For instance, there are fewer than 300 possible values for ga:country, so when segmenting only by country, you can't get more than 300 rows, even if you set pageSize to a higher value.

So this should work via setPageSize:

$request->setPageSize(10);
like image 74
Eike Pierstorff Avatar answered Aug 05 '26 22:08

Eike Pierstorff