From e66fa8f474a981e7335d999fd788014a9ba473b7 Mon Sep 17 00:00:00 2001 From: Alexander Kellner Date: Wed, 21 Feb 2024 20:10:41 +0100 Subject: [PATCH] [FEATURE] Add pagevisit to search tracking --- Classes/Controller/FrontendController.php | 2 +- Classes/Domain/Tracker/SearchTracker.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/FrontendController.php b/Classes/Controller/FrontendController.php index 097e5e16..2f3d47de 100644 --- a/Classes/Controller/FrontendController.php +++ b/Classes/Controller/FrontendController.php @@ -111,7 +111,7 @@ public function pageRequestAction(string $identificator, array $arguments): Resp $newsTracker = GeneralUtility::makeInstance(NewsTracker::class); $newsTracker->track($visitor, $arguments, $pagevisit); $searchTracker = GeneralUtility::makeInstance(SearchTracker::class); - $searchTracker->track($visitor, $arguments); + $searchTracker->track($visitor, $arguments, $pagevisit); return $this->jsonResponse(json_encode($this->afterAction($visitor))); } catch (Throwable $exception) { return $this->jsonResponse(json_encode($this->getError($exception))); diff --git a/Classes/Domain/Tracker/SearchTracker.php b/Classes/Domain/Tracker/SearchTracker.php index 24b3d608..8c46a616 100644 --- a/Classes/Domain/Tracker/SearchTracker.php +++ b/Classes/Domain/Tracker/SearchTracker.php @@ -4,6 +4,7 @@ namespace In2code\Lux\Domain\Tracker; use Doctrine\DBAL\DBALException; +use In2code\Lux\Domain\Model\Pagevisit; use In2code\Lux\Domain\Model\Search; use In2code\Lux\Domain\Model\Visitor; use In2code\Lux\Domain\Repository\VisitorRepository; @@ -37,10 +38,10 @@ public function __construct(VisitorRepository $visitorRepository, EventDispatche /** * @param Visitor $visitor * @param array $arguments + * @param Pagevisit|null $pagevisit * @return void - * @throws DBALException */ - public function track(Visitor $visitor, array $arguments): void + public function track(Visitor $visitor, array $arguments, Pagevisit $pagevisit = null): void { if ($this->isTrackingActivated($visitor, $arguments)) { $searchTerm = $this->getSearchTerm($arguments['currentUrl']); @@ -51,6 +52,9 @@ public function track(Visitor $visitor, array $arguments): void 'crdate' => time(), 'tstamp' => time(), ]; + if ($pagevisit !== null) { + $properties['pagevisit'] = $pagevisit->getUid(); + } $queryBuilder->insert(Search::TABLE_NAME)->values($properties)->executeStatement(); $searchUid = $queryBuilder->getConnection()->lastInsertId(); $this->eventDispatcher->dispatch(