src/AnalyticsClient.php
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) {
            $result = $this->service->data_ga->get(
                "ga:{$viewId}",
                $startDate->format('Y-m-d'),
                $endDate->format('Y-m-d'),
                $metrics,
                $others
            );

            while ($nextLink = $result->getNextLink()) {
                if (isset($others['max-results']) && count($result->rows) >= $others['max-results']) {
                    break;
                }

                $options = [];

                parse_str(substr($nextLink, strpos($nextLink, '?') + 1), $options);

                $response = $this->service->data_ga->call('get', [$options], 'Google_Service_Analytics_GaData');

                if ($response->rows) {
                    $result->rows = array_merge($result->rows, $response->rows);
                }

                $result->nextLink = $response->nextLink;
            }

            return $result;
        });
    }
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) {
            $result = $this->service->data_ga->get(
                "ga:{$viewId}",
                $startDate->format('Y-m-d'),
                $endDate->format('Y-m-d'),
                $metrics,
                $others
            );

            while ($nextLink = $result->getNextLink()) {
                if (isset($others['max-results']) && count($result->rows) >= $others['max-results']) {
                    break;
                }

                $options = [];

                parse_str(substr($nextLink, strpos($nextLink, '?') + 1), $options);

                $response = $this->service->data_ga->call('get', [$options], 'Google_Service_Analytics_GaData');

                if ($response->rows) {
                    $result->rows = array_merge($result->rows, $response->rows);
                }

                $result->nextLink = $response->nextLink;
            }

            return $result;
        });
    }
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 ) { $ result = $ this -> service -> data_ga -> get ( "ga:{$viewId}" , $ startDate -> format ( 'Y-m-d' ) , $ endDate -> format ( 'Y-m-d' ) , $ metrics , $ others ) ; while ( $ nextLink = $ result -> getNextLink ( ) ) { if ( isset ( $ others [ 'max-results' ] ) && count ( $ result -> rows ) >= $ others [ 'max-results' ] ) { break ; } $ options = [ ] ; parse_str ( substr ( $ nextLink , strpos ( $ nextLink , '?' ) + 1 ) , $ options ) ; $ response = $ this -> service -> data_ga -> call ( 'get' , [ $ options ] , 'Google_Service_Analytics_GaData' ) ; if ( $ response -> rows ) { $ result -> rows = array_merge ( $ result -> rows , $ response -> rows ) ; } $ result -> nextLink = $ response -> nextLink ; } return $ result ; } ) ; }
Query the Google Analytics Service with given parameters.

@param string $viewId
@param \DateTime $startDate
@param \DateTime $endDate
@param string $metrics
@param array $others

@return array|null
Query the Google Analytics Service with given parameters .