Spatie\Analytics\AnalyticsClient::performQuery PHP Method

performQuery() public method

Query the Google Analytics Service with given parameters.
public performQuery ( string $viewId, DateTime $startDate, DateTime $endDate, string $metrics, array $others = [] ) : array | null
$viewId string
$startDate DateTime
$endDate DateTime
$metrics string
$others array
return array | null
    public function performQuery(string $viewId, DateTime $startDate, DateTime $endDate, string $metrics, array $others = [])
    {
        $cacheName = $this->determineCacheName(func_get_args());
        if ($this->cacheLifeTimeInMinutes == 0) {
            $this->cache->forget($cacheName);
        }
        return $this->cache->remember($cacheName, $this->cacheLifeTimeInMinutes, function () use($viewId, $startDate, $endDate, $metrics, $others) {
            return $this->service->data_ga->get("ga:{$viewId}", $startDate->format('Y-m-d'), $endDate->format('Y-m-d'), $metrics, $others);
        });
    }

Usage Example

Esempio n. 1
0
 /**
  * Call the query method on the authenticated client.
  *
  * @param Period $period
  * @param string $metrics
  * @param array  $others
  *
  * @return array|null
  */
 public function performQuery(Period $period, string $metrics, array $others = [])
 {
     return $this->client->performQuery($this->viewId, $period->startDate, $period->endDate, $metrics, $others);
 }