diff --git a/index.html b/index.html index 8ec95f3..822f816 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ + diff --git a/src/services/analytics.ts b/src/services/analytics.ts new file mode 100644 index 0000000..8e89abe --- /dev/null +++ b/src/services/analytics.ts @@ -0,0 +1,30 @@ +export function initAnalytics() { + if (window.location.protocol != 'https:') { return } + + let _paq = window._paq = window._paq || []; + _paq.push(["setExcludedQueryParams", ['fbclid']]); + _paq.push(['setTrackerUrl', 'https://mackuba.eu/stat/matomo.php']); + _paq.push(['setCustomUrl', anonymizeParams(location.href)]); + _paq.push(["setRequestMethod", "GET"]); + _paq.push(['setSiteId', '13']); + _paq.push(["disableCookies"]); + _paq.push(["disableAlwaysUseSendBeacon"]); + _paq.push(['trackPageView']); +} + +function anonymizeParams(url: string) { + let u = new URL(url); + let params = u.searchParams; + + // turn e.g.: /?author=jcsalterego.bsky.social&post=3mci5wurx6c2c + // into: /?author=xxx&post=xxx + + for (let key of params.keys()) { + if (['q', 'author', 'post', 'quotes', 'hash'].includes(key)) { + params.set(key, 'xxx'); + } + } + + u.search = params.toString(); + return u.origin + u.pathname + u.search; +} diff --git a/src/skythread.ts b/src/skythread.ts index 5c731b6..072408f 100644 --- a/src/skythread.ts +++ b/src/skythread.ts @@ -1,6 +1,7 @@ import { mount } from 'svelte'; import { parseURLParams } from './router.js'; import App from './App.svelte'; +import { initAnalytics } from './services/analytics.js'; function init() { let params = parseURLParams(location.search); @@ -8,3 +9,4 @@ function init() { } document.addEventListener("DOMContentLoaded", init); +initAnalytics(); diff --git a/src/types.d.ts b/src/types.d.ts index 3731149..b7e4e9f 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,6 +1,7 @@ interface Window { root: AnyPost; subtreeRoot: AnyPost; + _paq?: any[][]; } type json = Record;