Thread viewer for Bluesky

added matomo analytics

+35 -1
+2 -1
index.html
··· 4 4 <meta charset="UTF-8"> 5 5 <meta http-equiv="Content-Security-Policy" content=" 6 6 default-src 'none'; 7 - script-src 'self'; 7 + script-src 'self' https://mackuba.eu; 8 8 style-src 'self'; 9 9 img-src 'self' https:; 10 10 font-src 'self'; ··· 26 26 </head> 27 27 <body> 28 28 <script src="dist/skythread.js"></script> 29 + <script src="https://mackuba.eu/stat/matomo.js"></script> 29 30 </body> 30 31 </html>
+30
src/services/analytics.ts
··· 1 + export function initAnalytics() { 2 + if (window.location.protocol != 'https:') { return } 3 + 4 + let _paq = window._paq = window._paq || []; 5 + _paq.push(["setExcludedQueryParams", ['fbclid']]); 6 + _paq.push(['setTrackerUrl', 'https://mackuba.eu/stat/matomo.php']); 7 + _paq.push(['setCustomUrl', anonymizeParams(location.href)]); 8 + _paq.push(["setRequestMethod", "GET"]); 9 + _paq.push(['setSiteId', '13']); 10 + _paq.push(["disableCookies"]); 11 + _paq.push(["disableAlwaysUseSendBeacon"]); 12 + _paq.push(['trackPageView']); 13 + } 14 + 15 + function anonymizeParams(url: string) { 16 + let u = new URL(url); 17 + let params = u.searchParams; 18 + 19 + // turn e.g.: /?author=jcsalterego.bsky.social&post=3mci5wurx6c2c 20 + // into: /?author=xxx&post=xxx 21 + 22 + for (let key of params.keys()) { 23 + if (['q', 'author', 'post', 'quotes', 'hash'].includes(key)) { 24 + params.set(key, 'xxx'); 25 + } 26 + } 27 + 28 + u.search = params.toString(); 29 + return u.origin + u.pathname + u.search; 30 + }
+2
src/skythread.ts
··· 1 1 import { mount } from 'svelte'; 2 2 import { parseURLParams } from './router.js'; 3 3 import App from './App.svelte'; 4 + import { initAnalytics } from './services/analytics.js'; 4 5 5 6 function init() { 6 7 let params = parseURLParams(location.search); ··· 8 9 } 9 10 10 11 document.addEventListener("DOMContentLoaded", init); 12 + initAnalytics();
+1
src/types.d.ts
··· 1 1 interface Window { 2 2 root: AnyPost; 3 3 subtreeRoot: AnyPost; 4 + _paq?: any[][]; 4 5 } 5 6 6 7 type json = Record<string, any>;