| @@ 43-58 (lines=16) @@ | ||
| 40 | return $this; |
|
| 41 | } |
|
| 42 | ||
| 43 | public function fetchVisitorsAndPageViews(Period $period): Collection |
|
| 44 | { |
|
| 45 | $response = $this->performQuery( |
|
| 46 | $period, |
|
| 47 | 'ga:users,ga:pageviews', |
|
| 48 | ['dimensions' => 'ga:date'] |
|
| 49 | ); |
|
| 50 | ||
| 51 | return collect($response['rows'] ?? [])->map(function (array $dateRow) { |
|
| 52 | return [ |
|
| 53 | 'date' => Carbon::createFromFormat('Ymd', $dateRow[0]), |
|
| 54 | 'visitors' => (int) $dateRow[1], |
|
| 55 | 'pageViews' => (int) $dateRow[2], |
|
| 56 | ]; |
|
| 57 | }); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function fetchMostVisitedPages(Period $period, int $maxResults = 20): Collection |
|
| 61 | { |
|
| @@ 60-79 (lines=20) @@ | ||
| 57 | }); |
|
| 58 | } |
|
| 59 | ||
| 60 | public function fetchMostVisitedPages(Period $period, int $maxResults = 20): Collection |
|
| 61 | { |
|
| 62 | $response = $this->performQuery( |
|
| 63 | $period, |
|
| 64 | 'ga:pageviews', |
|
| 65 | [ |
|
| 66 | 'dimensions' => 'ga:pagePath', |
|
| 67 | 'sort' => '-ga:pageviews', |
|
| 68 | 'max-results' => $maxResults, |
|
| 69 | ] |
|
| 70 | ); |
|
| 71 | ||
| 72 | return collect($response['rows'] ?? []) |
|
| 73 | ->map(function (array $pageRow) { |
|
| 74 | return [ |
|
| 75 | 'url' => $pageRow[0], |
|
| 76 | 'pageViews' => (int) $pageRow[1], |
|
| 77 | ]; |
|
| 78 | }); |
|
| 79 | } |
|
| 80 | ||
| 81 | public function fetchTopReferrers(Period $period, int $maxResults = 20): Collection |
|
| 82 | { |
|
| @@ 81-98 (lines=18) @@ | ||
| 78 | }); |
|
| 79 | } |
|
| 80 | ||
| 81 | public function fetchTopReferrers(Period $period, int $maxResults = 20): Collection |
|
| 82 | { |
|
| 83 | $response = $this->performQuery($period, |
|
| 84 | 'ga:pageviews', |
|
| 85 | [ |
|
| 86 | 'dimensions' => 'ga:fullReferrer', |
|
| 87 | 'sort' => '-ga:pageviews', |
|
| 88 | 'max-results' => $maxResults, |
|
| 89 | ] |
|
| 90 | ); |
|
| 91 | ||
| 92 | return collect($response['rows'] ?? [])->map(function (array $pageRow) { |
|
| 93 | return [ |
|
| 94 | 'url' => $pageRow[0], |
|
| 95 | 'pageViews' => (int) $pageRow[1], |
|
| 96 | ]; |
|
| 97 | }); |
|
| 98 | } |
|
| 99 | ||
| 100 | public function fetchTopBrowsers(Period $period, int $maxResults = 10): Collection |
|
| 101 | { |
|