| @@ 48-64 (lines=17) @@ | ||
| 45 | return $this->viewId; |
|
| 46 | } |
|
| 47 | ||
| 48 | public function fetchVisitorsAndPageViews(Period $period): Collection |
|
| 49 | { |
|
| 50 | $response = $this->performQuery( |
|
| 51 | $period, |
|
| 52 | 'ga:users,ga:pageviews', |
|
| 53 | ['dimensions' => 'ga:date,ga:pageTitle'] |
|
| 54 | ); |
|
| 55 | ||
| 56 | return collect($response['rows'] ?? [])->map(function (array $dateRow) { |
|
| 57 | return [ |
|
| 58 | 'date' => Carbon::createFromFormat('Ymd', $dateRow[0]), |
|
| 59 | 'pageTitle' => $dateRow[1], |
|
| 60 | 'visitors' => (int) $dateRow[2], |
|
| 61 | 'pageViews' => (int) $dateRow[3], |
|
| 62 | ]; |
|
| 63 | }); |
|
| 64 | } |
|
| 65 | ||
| 66 | public function fetchTotalVisitorsAndPageViews(Period $period): Collection |
|
| 67 | { |
|
| @@ 66-81 (lines=16) @@ | ||
| 63 | }); |
|
| 64 | } |
|
| 65 | ||
| 66 | public function fetchTotalVisitorsAndPageViews(Period $period): Collection |
|
| 67 | { |
|
| 68 | $response = $this->performQuery( |
|
| 69 | $period, |
|
| 70 | 'ga:users,ga:pageviews', |
|
| 71 | ['dimensions' => 'ga:date'] |
|
| 72 | ); |
|
| 73 | ||
| 74 | return collect($response['rows'] ?? [])->map(function (array $dateRow) { |
|
| 75 | return [ |
|
| 76 | 'date' => Carbon::createFromFormat('Ymd', $dateRow[0]), |
|
| 77 | 'visitors' => (int) $dateRow[1], |
|
| 78 | 'pageViews' => (int) $dateRow[2], |
|
| 79 | ]; |
|
| 80 | }); |
|
| 81 | } |
|
| 82 | ||
| 83 | public function fetchMostVisitedPages(Period $period, int $maxResults = 20): Collection |
|
| 84 | { |
|
| @@ 83-103 (lines=21) @@ | ||
| 80 | }); |
|
| 81 | } |
|
| 82 | ||
| 83 | public function fetchMostVisitedPages(Period $period, int $maxResults = 20): Collection |
|
| 84 | { |
|
| 85 | $response = $this->performQuery( |
|
| 86 | $period, |
|
| 87 | 'ga:pageviews', |
|
| 88 | [ |
|
| 89 | 'dimensions' => 'ga:pagePath,ga:pageTitle', |
|
| 90 | 'sort' => '-ga:pageviews', |
|
| 91 | 'max-results' => $maxResults, |
|
| 92 | ] |
|
| 93 | ); |
|
| 94 | ||
| 95 | return collect($response['rows'] ?? []) |
|
| 96 | ->map(function (array $pageRow) { |
|
| 97 | return [ |
|
| 98 | 'url' => $pageRow[0], |
|
| 99 | 'pageTitle' => $pageRow[1], |
|
| 100 | 'pageViews' => (int) $pageRow[2], |
|
| 101 | ]; |
|
| 102 | }); |
|
| 103 | } |
|
| 104 | ||
| 105 | public function fetchTopReferrers(Period $period, int $maxResults = 20): Collection |
|
| 106 | { |
|
| @@ 105-122 (lines=18) @@ | ||
| 102 | }); |
|
| 103 | } |
|
| 104 | ||
| 105 | public function fetchTopReferrers(Period $period, int $maxResults = 20): Collection |
|
| 106 | { |
|
| 107 | $response = $this->performQuery($period, |
|
| 108 | 'ga:pageviews', |
|
| 109 | [ |
|
| 110 | 'dimensions' => 'ga:fullReferrer', |
|
| 111 | 'sort' => '-ga:pageviews', |
|
| 112 | 'max-results' => $maxResults, |
|
| 113 | ] |
|
| 114 | ); |
|
| 115 | ||
| 116 | return collect($response['rows'] ?? [])->map(function (array $pageRow) { |
|
| 117 | return [ |
|
| 118 | 'url' => $pageRow[0], |
|
| 119 | 'pageViews' => (int) $pageRow[1], |
|
| 120 | ]; |
|
| 121 | }); |
|
| 122 | } |
|
| 123 | ||
| 124 | public function fetchUserTypes(Period $period): Collection |
|
| 125 | { |
|