我能够从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 );
}
这将返回GA中的所有综合浏览量。但我想获取特殊URL的页面视图。
我正在使用PHP Server Application GA API。
答案 0 :(得分:0)
最后,我找到了如何获取特殊网址的视图
$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结果