Fix tests for when window._paq is not set
This commit is contained in:
parent
a98935a87f
commit
9ce7ebcffb
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue