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