2016-07-11 6 views
1

GoogleアナリティクスAPI(PHPクライアントライブラリ - サーバー間のサービスとして)を使用すると、何度も空の結果セットが返されます。 私のコードを見ては、このような:GoogleアナリティクスAPIが空の結果を返すことがあります

public function getLeadDetails($view, $gauid, $lead_id,$refresh_token,$dates = []) 
{ 
    Log::info("*****************GA Service - GAUID: ".$gauid." **********************************"); 
    $options['dimensions'] = implode(',',config('analytics.dimensions')); 
    $options['filters'] = "ga:eventAction==".$gauid; 
    $metrics = "ga:users"; 
    $view = "ga:".$view; 
    $yesterday = date('Y-m-d',strtotime('yesterday')); 
    $tomorrow = date("Y-m-d",strtotime('tomorrow')); 
    if(count($dates)){ 
     $yesterday = $dates['yesterday']; 
     $tomorrow = $dates['tomorrow']; 
    } 
    Log::info('[email protected](), Request Params: ?ids='.$view.'&start-date='.$yesterday.'&end-date='.$tomorrow.'&metrics='.$metrics.'&dimensions='.$options['dimensions'].'&filters='.$options['filters']); 
    try{ 
     $this->client->setAccessType('offline'); 
     $this->client->setAccessToken($refresh_token); 
     $this->client->setClientId(config('analytics.client_id')); 
     $this->client->setScopes([ 
      \Google_Service_Analytics::ANALYTICS, 
      \Google_Service_Analytics::ANALYTICS_EDIT, 
     ]); 
     $analytics = new \Google_Service_Analytics($this->client); 
     $data = $analytics->data_ga->get($view,$yesterday,$tomorrow,$metrics,$options); 
     if($data['totalResults'] && $data['totalResults'] > 0){ 
      Log::info('Inside [email protected] has totalResults'); 
      $rtn = []; 
      $i = 0; 
      foreach ($data['rows'] as $row) { 
       $rtn['uacid'] = $gauid; 
       $rtn['user_type'] = $row[0]; 
       $rtn['device_category'] = $row[1]; 
       $rtn['source'] = $row[2]; 
       $rtn['medium'] = $row[3]; 
       $rtn['campaign'] = $row[4]; 
       $rtn['ad_group'] = $row[5]; 
       $rtn['path'] = $row[6]; 
       $i++; 
      } 
      Log::info('Inside [email protected] lead '.$lead_id.' should be update'); 
      return $this->insertLeadDetails($rtn , $lead_id); 
     } 
     Log::info('GA_Service::getLeadDetails() returned empty results for lead: '.$lead_id); 
     if(!count($dates)){ 
      $this->throwException('empty results for lead: '.$lead_id.' in GA_Service::getLeadDetails()',275); 
      return false; 
     } 
     return 'empty results for lead: '.$lead_id.' in GA_Service::getLeadDetails()'; 
    }catch (\Google_Service_Exception $e){ 
     Log::info('Google service exception from GA_Service::getLeadDetails() - '. $e->getErrors()[0]['message']); 
     $this->throwException($e->getErrors()[0]['message'], 335); 
    } 
    return false; 
} 

この関数火再び5分ごとに結果が(5回)空で、まだいくつかの結果を見逃した場合。

任意のアイデア理由と解決方法を教えてください。

答えて

1

なぜ5分ごとに発砲していますか?

コアのレポートAPIのデータは、24〜48時間安定しません。その後は変更されないので、あなたがそれをどこかで保存していると仮定して再度要求する理由はありません。

Data processing latency

処理レイテンシは24〜48時間です。 Analyticsに1日あたり200,000セッションを超える を送信する標準アカウントの場合、レポート は1日に1回しかリフレッシュされません。これにより、レポートと最大2日間のメトリック の更新が遅れることがあります。日中の処理を復元するには、 のアカウントを1日に< 200000に送信するセッション数を減らしてください。 プレミアムアカウントの場合、この制限は月に20億ヒットに拡張されます。

処理が完了していないため、おそらくデータが表示されないことがあります。

リアルタイム情報が必要な場合は、real-time apiを使用する必要があります。

+1

ありがとう、おそらくこの部分を逃した。 – benjah

関連する問題