我正在尝试使我们所有网站的报告自动化,并从指定的日期范围取回数据,但结果却有所不同。
新用户和回头用户
这就是我从Google Analytics(分析)网站获得的信息:
用户:1,513
新用户:1,406
回头客:220
会话:1,755
通过API
您可以看到回访者不匹配。
这是我正在使用的代码。
function getUserTypeReport($view, $analytics) {
$VIEW_ID = $view;
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("2019-05-01");
$dateRange->setEndDate("2019-05-31");
// Create the Metrics object.
$users = new Google_Service_AnalyticsReporting_Metric();
$users->setExpression("ga:users");
$users->setAlias("users");
// Create the Dimension object.
$userType = new Google_Service_AnalyticsReporting_Dimension();
$userType->setName("ga:userType");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setDimensions(array($userType));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
渠道维度也是如此:
function getMonthChannelReport($view, $analytics) {
$VIEW_ID = $view;
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("2019-05-01");
$dateRange->setEndDate("2019-05-31");
// Create the Metrics object.
$users = new Google_Service_AnalyticsReporting_Metric();
$users->setExpression("ga:users");
$users->setAlias("users");
// Create the Dimension object.
$aquisition = new Google_Service_AnalyticsReporting_Dimension();
$aquisition->setName("ga:acquisitionTrafficChannel");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setDimensions(array($aquisition));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
这是API中的数据
这是来自网站的数据:
我做错什么了吗?