mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Track short URL title as document title when sending visits to matomo
This commit is contained in:
@@ -13,14 +13,14 @@ use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
use Throwable;
|
||||
|
||||
class SendVisitToMatomo
|
||||
readonly class SendVisitToMatomo
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly ShortUrlStringifier $shortUrlStringifier,
|
||||
private readonly MatomoOptions $matomoOptions,
|
||||
private readonly MatomoTrackerBuilderInterface $trackerBuilder,
|
||||
private EntityManagerInterface $em,
|
||||
private LoggerInterface $logger,
|
||||
private ShortUrlStringifier $shortUrlStringifier,
|
||||
private MatomoOptions $matomoOptions,
|
||||
private MatomoTrackerBuilderInterface $trackerBuilder,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ class SendVisitToMatomo
|
||||
$tracker->setCustomTrackingParameter('orphan', 'true');
|
||||
}
|
||||
|
||||
// Send empty document title to avoid different actions to be created by matomo
|
||||
$tracker->doTrackPageView('');
|
||||
// Send the short URL title or an empty document title to avoid different actions to be created by matomo
|
||||
$tracker->doTrackPageView($visit->shortUrl?->title() ?? '');
|
||||
} catch (Throwable $e) {
|
||||
// Capture all exceptions to make sure this does not interfere with the regular execution
|
||||
$this->logger->error('An error occurred while trying to send visit to Matomo. {e}', ['e' => $e]);
|
||||
|
||||
@@ -192,6 +192,11 @@ class ShortUrl extends AbstractEntity
|
||||
return $this->forwardQuery;
|
||||
}
|
||||
|
||||
public function title(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function reachedVisits(int $visitsAmount): bool
|
||||
{
|
||||
return count($this->visits) >= $visitsAmount;
|
||||
|
||||
@@ -72,7 +72,7 @@ class SendVisitToMatomoTest extends TestCase
|
||||
$tracker->expects($this->once())->method('setUrl')->willReturn($tracker);
|
||||
$tracker->expects($this->once())->method('setUserAgent')->willReturn($tracker);
|
||||
$tracker->expects($this->once())->method('setUrlReferrer')->willReturn($tracker);
|
||||
$tracker->expects($this->once())->method('doTrackPageView')->with('');
|
||||
$tracker->expects($this->once())->method('doTrackPageView')->with($visit->shortUrl?->title() ?? '');
|
||||
|
||||
if ($visit->isOrphan()) {
|
||||
$tracker->expects($this->exactly(2))->method('setCustomTrackingParameter')->willReturnMap([
|
||||
|
||||
Reference in New Issue
Block a user