chengwl 4 vuotta sitten
vanhempi
commit
bbf58e353c
2 muutettua tiedostoa jossa 22 lisäystä ja 19 poistoa
  1. 20 2
      controllers/IndexController.php
  2. 2 17
      lib/GA.php

+ 20 - 2
controllers/IndexController.php

@@ -293,10 +293,28 @@ class IndexController extends \app\controllers\HomeController
       if(!$store){
          $this->json(0,[],'参数错误');
       }
+      $metricArr=[
+        'pageviews'=>"ga:pageviews",
+        'sessionCount'=>"ga:sessionCount",
+        'users'=>"ga:users",
+        'newUsers'=>"ga:newUsers",
+        'bounceRate'=>"ga:bounceRate",
+        'goal3Completions'=>"ga:goal3Completions",
+        'goal3ConversionRate'=>"ga:goal3ConversionRate",
+        'goal7Completions'=>"ga:goal7Completions",
+        'goal7ConversionRate'=>"ga:goal7ConversionRate",
+        'transactionRevenue'=>"ga:transactionRevenue",
+        'revenuePerTransaction'=>"ga:revenuePerTransaction",
+    ];
       $start_day=$request->get('start', date('Y-m-d',time()-3600*24));
       $end_day = $request->get('end', date('Y-m-d',time()-3600*24));
-      $goals=$ga->goals($store,$start_day,$end_day);
-      $this->json(1,$goals);      
+      $chunks=array_chunk($metricArr,10);
+      $data=[];
+      foreach($chunks as $arr){
+        $goals=$ga->goals($store,$arr,$start_day,$end_day);
+        $data=empty($goals)?$goals:array_merge_recursive($data,$goals);
+      }
+      $this->json(1,$data);      
     }
 
   }

+ 2 - 17
lib/GA.php

@@ -489,25 +489,10 @@ class GA{
          return $result;
 
     }
-    public function goals($dp,$start_at,$end_at){
+    public function goals($dp,$metricArr=[],$start_at,$end_at){
         $analytics=self::getInstance($dp);
         $dimensionArr=[
-            'date'=>'ga:date',
-        ];
-        $metricArr=[
-            'pageviews'=>"ga:pageviews",
-            'sessionCount'=>"ga:sessionCount",
-            'users'=>"ga:users",
-            'newUsers'=>"ga:newUsers",
-            'bounceRate'=>"ga:bounceRate",
-            'goal3Completions'=>"ga:goal3Completions",
-            'goal3ConversionRate'=>"ga:goal3ConversionRate",
-            'goal7Completions'=>"ga:goal7Completions",
-            'goal7ConversionRate'=>"ga:goal7ConversionRate",
-            'transactionRevenue'=>"ga:transactionRevenue",
-            'revenuePerTransaction'=>"ga:revenuePerTransaction",
-            
-            
+            // 'date'=>'ga:date',
         ];
        
         $VIEW_ID = $this->getViewId($dp);//