예제 #1
0
 /**
  * Get google Analytic data from google.
  * If we use google batch, each query to get data will move to batch queue
  * @param  array/string $listGA google dimensions
  * @param  datetime $from   start time to get analytic data
  * @param  datetime $to     end time to get analytic data
  * @param  string $prefix [for batch]. separate different query
  * @return [mixed]
  */
 public function getAnalyticData($listGA, $from, $to, $prefix)
 {
     $profileID = Settings::getAnalyticProfileID();
     if ($profileID) {
         $accountID = Settings::getAnalyticAccountID();
         $service = new \Google_Service_Analytics($this->client);
         if (is_array($listGA)) {
             $metrics = implode(',', $listGA);
         } else {
             $metrics = $listGA;
         }
         if ($this->useBatch) {
             $data = $service->data_ga->get('ga:' . $profileID, $from, $to, $metrics);
             $this->batch->add($data, $metrics . $prefix);
             return true;
         } else {
             $data = $service->data_ga->get('ga:' . $profileID, $from, $to, $metrics);
             return $data['rows'][0];
         }
     }
     return false;
 }