Fix tests for when window._paq is not set

This commit is contained in:
Ramon Wenger 2023-04-12 21:14:01 +02:00
parent a98935a87f
commit 9ce7ebcffb
1 changed files with 8 additions and 2 deletions

View File

@ -13,6 +13,14 @@ let matomoLastUrl = '';
let matomoLastUserId = '';
let matomoLastEventData = '';
declare global {
interface Window {
_paq: any[];
}
}
window._paq = window._paq || [];
export function matomoTrackPageView(absolutePath: string = '/', title?: string) {
// see https://developer.matomo.org/guides/spa-tracking for details
const url = window.location.origin + absolutePath;
@ -20,9 +28,7 @@ export function matomoTrackPageView(absolutePath: string = '/', title?: string)
if (matomoLastUrl !== url) {
// do not track the same url twice
log.debug('trackMatomoPageView', { url, matomoLastUrl, title });
// @ts-ignore
window._paq.push(['setCustomUrl', url]);
// @ts-ignore
window._paq.push(['trackPageView', title]);
matomoLastUrl = url;
}