|
@@ -63,8 +63,31 @@ class IndexController extends Controller
|
|
{
|
|
{
|
|
|
|
|
|
$analytics=$this->initializeAnalytics();
|
|
$analytics=$this->initializeAnalytics();
|
|
- $response = $this->getReport($analytics);
|
|
|
|
- $this->printResults($response);
|
|
|
|
|
|
+ $metricsArr=[
|
|
|
|
+ 'sessions'=>"ga:sessions",
|
|
|
|
+ 'bounceRate'=>"ga:bounceRate",
|
|
|
|
+ 'sessionDuration'=>"ga:sessionDuration",
|
|
|
|
+ 'bounceRate'=>"ga:bounceRate",
|
|
|
|
+ 'hits'=>"ga:hits",
|
|
|
|
+ 'transactions'=>"ga:transactions",
|
|
|
|
+ 'transactionsPerSession'=>"ga:transactionsPerSession",
|
|
|
|
+ 'transactionRevenue'=>"ga:transactionRevenue",
|
|
|
|
+ 'totalValue'=>"ga:totalValue",
|
|
|
|
+ 'itemQuantity'=>"ga:itemQuantity",
|
|
|
|
+ 'productAddsToCart'=>"ga:productAddsToCart",
|
|
|
|
+ 'productCheckouts'=>"ga:productCheckouts",
|
|
|
|
+ ];
|
|
|
|
+ $i=1;
|
|
|
|
+ $list=[];
|
|
|
|
+ foreach($metrics as $metric){
|
|
|
|
+ $lis[]=$metric;
|
|
|
|
+ if($i%10==0||count($metrics)==$i){
|
|
|
|
+ $response = $this->getReport($analytics);
|
|
|
|
+ $this->printResults($response);
|
|
|
|
+ $list=[];
|
|
|
|
+ }
|
|
|
|
+ $i++;
|
|
|
|
+ }
|
|
exit;
|
|
exit;
|
|
return $this->render('index');
|
|
return $this->render('index');
|
|
}
|
|
}
|
|
@@ -93,11 +116,8 @@ class IndexController extends Controller
|
|
* @param service An authorized Analytics Reporting API V4 service object.
|
|
* @param service An authorized Analytics Reporting API V4 service object.
|
|
* @return The Analytics Reporting API V4 response.
|
|
* @return The Analytics Reporting API V4 response.
|
|
*/
|
|
*/
|
|
-function getReport($analytics) {
|
|
|
|
-
|
|
|
|
- // Replace with your view ID, for example XXXX.
|
|
|
|
|
|
+function getReport($analytics,$metrics) {
|
|
$VIEW_ID = "155703065";
|
|
$VIEW_ID = "155703065";
|
|
-
|
|
|
|
// Create the DateRange object.
|
|
// Create the DateRange object.
|
|
$dateRange = new \Google_Service_AnalyticsReporting_DateRange();
|
|
$dateRange = new \Google_Service_AnalyticsReporting_DateRange();
|
|
$dateRange->setStartDate("7daysAgo");
|
|
$dateRange->setStartDate("7daysAgo");
|
|
@@ -105,86 +125,15 @@ function getReport($analytics) {
|
|
$metrics=[];
|
|
$metrics=[];
|
|
$dimensions=[];
|
|
$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);
|
|
|
|
-
|
|
|
|
|
|
+ foreach($metrics as $k=>$v){
|
|
|
|
+ $Metric = new \Google_Service_AnalyticsReporting_Metric();
|
|
|
|
+ $Metric->setExpression($v);
|
|
|
|
+ $Metric->setAlias($k);
|
|
|
|
+ array_push($metrics,$Metric);
|
|
|
|
+ }
|
|
$date = new \Google_Service_AnalyticsReporting_Dimension();
|
|
$date = new \Google_Service_AnalyticsReporting_Dimension();
|
|
$date->setName("ga:date");
|
|
$date->setName("ga:date");
|
|
array_push($dimensions,$date);
|
|
array_push($dimensions,$date);
|
|
-
|
|
|
|
-
|
|
|
|
- //交易次数
|
|
|
|
- $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);
|
|
|
|
-
|
|
|
|
- $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.
|
|
// Create the ReportRequest object.
|
|
$request = new \Google_Service_AnalyticsReporting_ReportRequest();
|
|
$request = new \Google_Service_AnalyticsReporting_ReportRequest();
|
|
$request->setViewId($VIEW_ID);
|
|
$request->setViewId($VIEW_ID);
|