chengwl 4 anni fa
parent
commit
b172bb7163
1 ha cambiato i file con 67 aggiunte e 6 eliminazioni
  1. 67 6
      controllers/IndexController.php

+ 67 - 6
controllers/IndexController.php

@@ -102,30 +102,91 @@ function getReport($analytics) {
   $dateRange = new \Google_Service_AnalyticsReporting_DateRange();
   $dateRange->setStartDate("7daysAgo");
   $dateRange->setEndDate("today");
+  $metrics=[];
+  $dimensions=[];
 
   // Create the Metrics object.
   $sessions = new \Google_Service_AnalyticsReporting_Metric();
   $sessions->setExpression("ga:sessions");
   $sessions->setAlias("sessions");
+  array_push($metrics,$sessions);
   
   $users = new \Google_Service_AnalyticsReporting_Metric();
   $users->setExpression("ga:users");
   $users->setAlias("users");
+  array_push($metrics,$users);
+
+  //跳出率
+  $bounceRate = new \Google_Service_AnalyticsReporting_Metric();
+  $bounceRate->setExpression("ga:bounceRate");
+  $bounceRate->setAlias("bounceRate");
+  array_push($metrics,$bounceRate);
+
+  //
+  $sessionDuration = new \Google_Service_AnalyticsReporting_Metric();
+  $sessionDuration->setExpression("ga:sessionDuration");
+  $sessionDuration->setAlias("sessionDuration");
+  array_push($metrics,$sessionDuration);
+  
+
+  $hits = new \Google_Service_AnalyticsReporting_Metric();
+  $hits->setExpression("ga:hits");
+  $hits->setAlias("hits");
+  array_push($metrics,$hits);
+  
+  //交易阶段 
+  $shoppingStage = new \Google_Service_AnalyticsReporting_Dimension();
+  $shoppingStage->setName("ga:shoppingStage");
+  array_push($dimensions,$shoppingStage);
+  
 
-  $source = new \Google_Service_AnalyticsReporting_Dimension();
-  $source->setName("ga:source");
+  //交易次数
+  $transactions = new \Google_Service_AnalyticsReporting_Metric();
+  $transactions->setExpression("ga:transactions");
+  $transactions->setAlias("transactions");
+  array_push($metrics,$transactions);
+
+  //电子商务转化率
+  $transactionsPerSession = new \Google_Service_AnalyticsReporting_Metric();
+  $transactionsPerSession->setExpression("ga:transactionsPerSession");
+  $transactionsPerSession->setAlias("transactionsPerSession");
+  array_push($metrics,$transactionsPerSession);
+ 
+  $transactionRevenue = new \Google_Service_AnalyticsReporting_Metric();
+  $transactionRevenue->setExpression("ga:transactionRevenue");
+  $transactionRevenue->setAlias("transactionRevenue");
+  array_push($metrics,$transactionRevenue);
+
+
+  //
+  $totalValue = new \Google_Service_AnalyticsReporting_Metric();
+  $totalValue->setExpression("ga:totalValue");
+  $totalValue->setAlias("totalValue");
+  array_push($metrics,$totalValue);
+  
+  
+  $itemQuantity = new \Google_Service_AnalyticsReporting_Metric();
+  $itemQuantity->setExpression("ga:itemQuantity");
+  $itemQuantity->setAlias("itemQuantity");
+  array_push($metrics,$itemQuantity);
 
-//   $segmentDimensions = new \Google_Service_AnalyticsReporting_Dimension();
-//   $segmentDimensions->setName("ga:segment");
+  $productAddsToCart = new \Google_Service_AnalyticsReporting_Metric();
+  $productAddsToCart->setExpression("ga:productAddsToCart");
+  $productAddsToCart->setAlias("productAddsToCart");
+  array_push($metrics,$productAddsToCart);
 
+  $productCheckouts = new \Google_Service_AnalyticsReporting_Metric();
+  $productCheckouts->setExpression("ga:productCheckouts");
+  $productCheckouts->setAlias("productCheckouts");
+  array_push($metrics,$productCheckouts);
 
 
   // Create the ReportRequest object.
   $request = new \Google_Service_AnalyticsReporting_ReportRequest();
   $request->setViewId($VIEW_ID);
   $request->setDateRanges($dateRange);
-  $request->setMetrics(array($sessions,$users));
-  $request->setDimensions(array($source));
+  $request->setMetrics($metrics);
+  $request->setDimensions($dimensions);
 
   $body = new \Google_Service_AnalyticsReporting_GetReportsRequest();
   $body->setReportRequests( array( $request) );