From 617e10b929f7777f464330ffe6d65b24d76d8ba4 Mon Sep 17 00:00:00 2001 From: Axel Ternisien Date: Mon, 8 Jan 2024 18:26:16 +0100 Subject: [PATCH] Update ViewsAnalytics.php Add a the function getViewsPageByPathUrl() to get views for a unique page. --- src/Traits/Analytics/ViewsAnalytics.php | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Traits/Analytics/ViewsAnalytics.php b/src/Traits/Analytics/ViewsAnalytics.php index 64deb9e..279f581 100644 --- a/src/Traits/Analytics/ViewsAnalytics.php +++ b/src/Traits/Analytics/ViewsAnalytics.php @@ -95,7 +95,33 @@ public function totalViewsByPagePath(Period $period): array return $this->getReport($googleAnalytics) ->dataTable; } + + /** + * @throws \Google\ApiCore\ApiException + * @throws \Google\ApiCore\ValidationException + */ + public function getViewsPageByPathUrl(Period $period, string $pagePath): array + { + try{ + $googleAnalytics = $this->googleAnalytics + ->setDateRange($period) + ->addMetrics('screenPageViews') + ->addDimensions('pagePath') + ->whereDimension('pagePath',4,$pagePath,true); + return $this->getReport($googleAnalytics) + ->dataTable; + + } catch (Throwable $e) { + + Log::channel('google')->info('Erreur API get '. $entityCode); + Log::channel('google')->info('Exception: '. $e); + report($e); + return false; + + } + } + /** * @throws \Google\ApiCore\ApiException * @throws \Google\ApiCore\ValidationException