public function fetchTopBrowsers(Period $period, int $maxResults = 10) : Collection
{
$response = $this->performQuery($period, 'ga:sessions', ['dimensions' => 'ga:browser', 'sort' => '-ga:sessions']);
$topBrowsers = collect($response['rows'] ?? [])->map(function (array $browserRow) {
return ['browser' => $browserRow[0], 'sessions' => (int) $browserRow[1]];
});
if ($topBrowsers->count() <= $maxResults) {
return $topBrowsers;
}
return $this->summarizeTopBrowsers($topBrowsers, $maxResults);
}