2022-07-07 11:39:03 +02:00
|
|
|
|
import { getConfig } from '@utils';
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
matomo: { cookieDomain, domain, enabled, host, key }
|
|
|
|
|
} = getConfig();
|
|
|
|
|
|
|
|
|
|
declare const window: Window &
|
|
|
|
|
typeof globalThis & { _paq: [key: string, value: unknown] };
|
2019-03-26 16:02:08 +01:00
|
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
|
window._paq = window._paq || [];
|
|
|
|
|
|
2022-01-18 12:47:01 +01:00
|
|
|
|
const jsUrl = `//${host}/piwik.js`;
|
|
|
|
|
const trackerUrl = `//${host}/piwik.php`;
|
2019-03-26 16:02:08 +01:00
|
|
|
|
|
2021-12-16 17:33:16 +01:00
|
|
|
|
//
|
2019-03-26 16:02:08 +01:00
|
|
|
|
// Configure Matomo analytics
|
2021-12-16 17:33:16 +01:00
|
|
|
|
//
|
|
|
|
|
|
2022-01-26 13:57:49 +01:00
|
|
|
|
window._paq.push(['setCookieDomain', cookieDomain]);
|
|
|
|
|
window._paq.push(['setDomains', [domain]]);
|
2021-12-16 17:33:16 +01:00
|
|
|
|
// Don’t store any cookies or send any tracking request when the "Do Not Track" browser setting is enabled.
|
2019-03-26 16:02:08 +01:00
|
|
|
|
window._paq.push(['setDoNotTrack', true]);
|
2021-12-16 17:33:16 +01:00
|
|
|
|
// When enabling external link tracking, consider that it will also report links to attachments.
|
|
|
|
|
// You’ll want to exclude links to attachments from being tracked – for instance using Matomo's
|
|
|
|
|
// `setCustomRequestProcessing` callback.
|
|
|
|
|
// window._paq.push(['enableLinkTracking']);
|
2019-03-26 16:02:08 +01:00
|
|
|
|
window._paq.push(['trackPageView']);
|
|
|
|
|
|
|
|
|
|
// Load script from Matomo
|
|
|
|
|
window._paq.push(['setTrackerUrl', trackerUrl]);
|
|
|
|
|
window._paq.push(['setSiteId', key]);
|
|
|
|
|
|
|
|
|
|
const script = document.createElement('script');
|
|
|
|
|
const firstScript = document.getElementsByTagName('script')[0];
|
|
|
|
|
script.type = 'text/javascript';
|
|
|
|
|
script.id = 'matomo-js';
|
|
|
|
|
script.async = true;
|
|
|
|
|
script.src = jsUrl;
|
2022-07-07 11:39:03 +02:00
|
|
|
|
firstScript.parentNode?.insertBefore(script, firstScript);
|
2019-03-26 16:02:08 +01:00
|
|
|
|
}
|