Pass visit date to matomo when tracking

This commit is contained in:
Alejandro Celaya 2024-04-12 18:47:12 +02:00
parent ca42425b33
commit 4fdbcc25a0
2 changed files with 8 additions and 1 deletions

View file

@ -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) {

View file

@ -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);