Skip to content

Commit

Permalink
[FEATURE] Add pagevisit to search tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 21, 2024
1 parent b49c34a commit e66fa8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Classes/Controller/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
8 changes: 6 additions & 2 deletions Classes/Domain/Tracker/SearchTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand All @@ -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(
Expand Down

0 comments on commit e66fa8f

Please sign in to comment.