GA php-服务器获得特殊页面浏览量

GA php-server get special page views

我能够从 https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php

运行 示例 PHP 快速入门
function getReport($analytics) {

    // Replace with your view ID, for example XXXX.
    $VIEW_ID = "XXXMY_VIEW_IDXXX";

    // Create the DateRange object.
    $dateRange = new Google_Service_AnalyticsReporting_DateRange();
    $dateRange->setStartDate("2018-11-19");
    $dateRange->setEndDate("2018-11-20");

    // Create the Metrics object.
    $sessions = new Google_Service_AnalyticsReporting_Metric();
    $sessions->setExpression("ga:sessions");
    $sessions->setAlias("sessions");

    $pageviews = new Google_Service_AnalyticsReporting_Metric();
    $pageviews->setExpression("ga:pageviews");
    $pageviews->setAlias("pageviews");

    // Create the ReportRequest object.
    $request = new Google_Service_AnalyticsReporting_ReportRequest();
    $request->setViewId($VIEW_ID);
    $request->setDateRanges($dateRange);
    $request->setMetrics(array($sessions, $pageviews));

    $body = new Google_Service_AnalyticsReporting_GetReportsRequest();
    $body->setReportRequests( array( $request) );
    return $analytics->reports->batchGet( $body );
}

即 returns GA 中的所有综合浏览量。但我想获得特殊 url.

的页面浏览量

我正在使用 PHP 服务器应用程序 GA API。

我终于找到了如何获得特别节目的观看次数 url

$filterPath = 'www.abc.com';
$filter = new \Google_Service_AnalyticsReporting_DimensionFilter();
$filter->setDimensionName( 'ga:pagePath' );
$filter->setOperator( 'BEGINS_WITH' );
$filter->setExpressions( [ $filterPath ] );

$filters = new \Google_Service_AnalyticsReporting_DimensionFilterClause();
$filters->setFilters([$filter]);

以上代码可以过滤以'www.abc.com'

开头的ga结果