Пример #1
0
 /**
  * Create a new instance via a set of parameters
  * 
  * @param  string $siteId
  *         Ex. ga:xxxxxxxx
  * @param  string $clientId
  *         Ex. xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
  * @param  string $serviceEmail
  *         Ex. xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com
  * @param  string $certificatePath
  *         Ex. /../keys/analytics/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-privatekey.p12
  * 
  * @param  \Spatie\Analytics\Cache|null $cache
  * @param  int $cacheLifetimeInMinutes
  * @param  int $realTimeCacheLifetime
  * 
  * @return \Spatie\Analytics\Analytics
  * 
  * @throws \Exception
  */
 public static function create($siteId, $clientId, $serviceEmail, $certificatePath, Cache $cache = null, $cacheLifetimeInMinutes = 0, $realTimeCacheLifetime = 0)
 {
     if (!file_exists($certificatePath)) {
         throw new Exception("Can't find the .p12 certificate in: {$certificatePath}");
     }
     $client = new Google_Client(array('oauth2_client_id' => $clientId, 'use_objects' => true));
     $client->setAccessType('offline');
     $client->setAssertionCredentials(new Google_Auth_AssertionCredentials($serviceEmail, array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents($certificatePath)));
     $googleApi = new GoogleClient($client, $cache);
     $googleApi->setCacheLifeTimeInMinutes($cacheLifetimeInMinutes)->setRealTimeCacheLifeTimeInMinutes($realTimeCacheLifetime);
     return new static($googleApi, $siteId);
 }
Пример #2
0
 /**
  * Call the real time query method on the authenticated client.
  *
  * @param  string $metrics
  * @param  array $others
  * @return mixed
  */
 public function performRealTimeQuery($metrics, $others = array())
 {
     return $this->client->performRealTimeQuery($this->siteId, $metrics, $others);
 }