public function getTopBrowsersForPeriod($startDate, $endDate, $maxResults)
    {
        $browserData = [];
        $answer = $this->performQuery($startDate, $endDate, 'ga:sessions', ['dimensions' => 'ga:browser', 'sort' => '-ga:sessions']);

        if (is_null($answer->rows)) {
            return new Collection([]);
        }

        foreach ($answer->rows as $browserRow) {
            $browserData[] = ['browser' => $browserRow[0], 'sessions' => $browserRow[1]];
        }

        $browserCollection = new Collection(array_slice($browserData, 0, $maxResults - 1));

        if (count($browserData) > $maxResults) {
            $otherBrowsers = new Collection(array_slice($browserData, $maxResults - 1));
            $otherBrowsersCount = array_sum($otherBrowsers->lists('sessions'));

            $browserCollection->put(null, ['browser' => 'other', 'sessions' => $otherBrowsersCount]);
        }

        return $browserCollection;
    }
public function getTopBrowsersForPeriod($startDate, $endDate, $maxResults)
    {
        $browserData = [];
        $answer = $this->performQuery($startDate, $endDate, 'ga:sessions', ['dimensions' => 'ga:browser', 'sort' => '-ga:sessions']);

        if (is_null($answer->rows)) {
            return new Collection([]);
        }

        foreach ($answer->rows as $browserRow) {
            $browserData[] = ['browser' => $browserRow[0], 'sessions' => $browserRow[1]];
        }

        $browserCollection = new Collection(array_slice($browserData, 0, $maxResults - 1));

        if (count($browserData) > $maxResults) {
            $otherBrowsers = new Collection(array_slice($browserData, $maxResults - 1));
            $otherBrowsersCount = array_sum($otherBrowsers->lists('sessions'));

            $browserCollection->put(null, ['browser' => 'other', 'sessions' => $otherBrowsersCount]);
        }

        return $browserCollection;
    }
public function getTopBrowsersForPeriod ( $ startDate , $ endDate , $ maxResults ) { $ browserData = [ ] ; $ answer = $ this -> performQuery ( $ startDate , $ endDate , 'ga:sessions' , [ 'dimensions' => 'ga:browser' , 'sort' => '-ga:sessions' ] ) ; if ( is_null ( $ answer -> rows ) ) { return new Collection ( [ ] ) ; } foreach ( $ answer -> rows as $ browserRow ) { $ browserData [ ] = [ 'browser' => $ browserRow [ 0 ] , 'sessions' => $ browserRow [ 1 ] ] ; } $ browserCollection = new Collection ( array_slice ( $ browserData , 0 , $ maxResults - 1 ) ) ; if ( count ( $ browserData ) > $ maxResults ) { $ otherBrowsers = new Collection ( array_slice ( $ browserData , $ maxResults - 1 ) ) ; $ otherBrowsersCount = array_sum ( $ otherBrowsers -> lists ( 'sessions' ) ) ; $ browserCollection -> put ( null , [ 'browser' => 'other' , 'sessions' => $ otherBrowsersCount ] ) ; } return $ browserCollection ; }
Get the top browsers for the given period.

@param \DateTime $startDate
@param \DateTime $endDate
@param $maxResults

@return Collection
Get the top browsers for the given period .