我正在使用通过 composer v2.0 安装的 google-api-php-client。我需要每天/每周/每月等提取数据。但是,我只得到总数。我可能遗漏了一处房产,但我在任何地方都找不到它应该是什么。这是我正在使用的请求$client = new Google_Client();$client->setClientId(GOOGLE_CLIENT_ID);$client->setClientSecret(GOOGLE_CLIENT_SECRET);$client->setRedirectUri(GOOGLE_REDIRECT_URL);$client->setAccessType('online'); // default: offline$client->setApplicationName('Login to my app');$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);$analytics = new Google_Service_AnalyticsReporting($client);function getReport($analytics, $profileId) { $VIEW_ID = $profileId; // Create the DateRange object. $dateRange = new Google_Service_AnalyticsReporting_DateRange(); $dateRange->setStartDate("7daysAgo"); $dateRange->setEndDate("today"); $dateRange2 = new Google_Service_AnalyticsReporting_DateRange(); $dateRange2->setStartDate("14daysAgo"); $dateRange2->setEndDate("7daysAgo"); // Create the Metrics object. $sessions = new Google_Service_AnalyticsReporting_Metric(); $sessions->setExpression("ga:sessions"); $sessions->setAlias("Sessions"); $new_users = new Google_Service_AnalyticsReporting_Metric(); $new_users->setExpression("ga:newUsers"); $new_users->setAlias("New users"); $organic = new Google_Service_AnalyticsReporting_Metric(); $organic->setExpression("ga:organicSearches"); $organic->setAlias("Organic results"); // Create the ReportRequest object. $request = new Google_Service_AnalyticsReporting_ReportRequest(); $request->setViewId($VIEW_ID); $request->setDateRanges(array($dateRange,$dateRange2)); $request->setMetrics(array($sessions, $new_users, $organic)); $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); $body->setReportRequests( array( $request) ); return $analytics->reports->batchGet( $body );}这仅返回我指定的日期范围的总数。我希望你能帮我找到丢失的财产或我做错了什么。谢谢你。
1 回答
桃花长相依
TA贡献1860条经验 获得超8个赞
您需要传递ga:date维度以按日期对结果进行分组。您可以使用 Google Analytics Dimensions and Metrics Explorer找到完整的指标和维度列表,并使用这些数据。正如您在评论中提到的,您可以将其添加到您的代码中:
$date = new Google_Service_AnalyticsReporting_Dimension();
$date->setName("ga:date");
$request->setDimensions(array($date));
- 1 回答
- 0 关注
- 149 浏览
添加回答
举报
0/150
提交
取消