From 4fdbcc25a0f33a76bc54212eebdca89409d35de3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 12 Apr 2024 18:47:12 +0200 Subject: [PATCH] Pass visit date to matomo when tracking --- module/Core/src/Matomo/MatomoVisitSender.php | 3 ++- module/Core/test/Matomo/MatomoVisitSenderTest.php | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/module/Core/src/Matomo/MatomoVisitSender.php b/module/Core/src/Matomo/MatomoVisitSender.php index 8caed3cc..c051516c 100644 --- a/module/Core/src/Matomo/MatomoVisitSender.php +++ b/module/Core/src/Matomo/MatomoVisitSender.php @@ -23,7 +23,8 @@ readonly class MatomoVisitSender implements MatomoVisitSenderInterface ->setUrl($this->resolveUrlToTrack($visit)) ->setCustomTrackingParameter('type', $visit->type->value) ->setUserAgent($visit->userAgent) - ->setUrlReferrer($visit->referer); + ->setUrlReferrer($visit->referer) + ->setForceVisitDateTime($visit->date->setTimezone('UTC')->toDateTimeString()); $location = $visit->getVisitLocation(); if ($location !== null) { diff --git a/module/Core/test/Matomo/MatomoVisitSenderTest.php b/module/Core/test/Matomo/MatomoVisitSenderTest.php index 3e08d6aa..90c52446 100644 --- a/module/Core/test/Matomo/MatomoVisitSenderTest.php +++ b/module/Core/test/Matomo/MatomoVisitSenderTest.php @@ -42,6 +42,9 @@ class MatomoVisitSenderTest extends TestCase $tracker->expects($this->once())->method('setUserAgent')->willReturn($tracker); $tracker->expects($this->once())->method('setUrlReferrer')->willReturn($tracker); $tracker->expects($this->once())->method('doTrackPageView')->with($visit->shortUrl?->title() ?? ''); + $tracker->expects($this->once())->method('setForceVisitDateTime')->with( + $visit->date->setTimezone('UTC')->toDateTimeString(), + ); if ($visit->isOrphan()) { $tracker->expects($this->exactly(2))->method('setCustomTrackingParameter')->willReturnMap([ @@ -93,6 +96,9 @@ class MatomoVisitSenderTest extends TestCase $tracker->expects($this->once())->method('setUrlReferrer')->willReturn($tracker); $tracker->expects($this->any())->method('setCustomTrackingParameter')->willReturn($tracker); $tracker->expects($this->once())->method('doTrackPageView'); + $tracker->expects($this->once())->method('setForceVisitDateTime')->with( + $visit->date->setTimezone('UTC')->toDateTimeString(), + ); $this->trackerBuilder->expects($this->once())->method('buildMatomoTracker')->willReturn($tracker);