Files
Stirling-PDF/frontend/src/utils/scarfTracking.ts
ConnorYoh 2f2f966ee9 Turn off logs from scarf (#4326)
Co-authored-by: Connor Yoh <connor@stirlingpdf.com>
2025-08-29 17:23:18 +01:00

27 lines
749 B
TypeScript

let lastFiredPathname: string | null = null;
let lastFiredTime = 0;
/**
* Fire scarf pixel for analytics tracking
* Only fires if pathname is different from last call or enough time has passed
*/
export function firePixel(pathname: string): void {
const now = Date.now();
// Only fire if pathname changed or it's been at least 1 second since last fire
if (pathname === lastFiredPathname && now - lastFiredTime < 250) {
return;
}
lastFiredPathname = pathname;
lastFiredTime = now;
const url = 'https://static.scarf.sh/a.png?x-pxid=3c1d68de-8945-4e9f-873f-65320b6fabf7'
+ '&path=' + encodeURIComponent(pathname)
const img = new Image();
img.referrerPolicy = "no-referrer-when-downgrade";
img.src = url;
}