PHP & Analytics API - 获取 10 行
PHP & Analytics API - Get 10 rows
我正在使用Google Analytics Core Reporting V4
使用以下代码,我正在设置 google 分析请求。
// 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);
如何让请求只获取最高的 10 个城市而忽略其余城市。
从文档看来 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.
所以这应该通过 setPageSize 起作用:
$request->setPageSize(10);
我正在使用Google Analytics Core Reporting V4
使用以下代码,我正在设置 google 分析请求。
// 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);
如何让请求只获取最高的 10 个城市而忽略其余城市。
从文档看来 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.
所以这应该通过 setPageSize 起作用:
$request->setPageSize(10);