Add sthe scarf pixel

This commit is contained in:
Connor Yoh 2025-08-27 13:57:29 +01:00
parent 67d456cb86
commit 89635b576c
2 changed files with 38 additions and 4 deletions

View File

@ -0,0 +1,33 @@
import { useLocation } from "react-router-dom";
import { useEffect, useRef } from "react";
export function ScarfPixel() {
const location = useLocation();
const lastUrlSent = useRef<string | null>(null); // helps with React 18 StrictMode in dev
useEffect(() => {
// Force reload of the tracking pixel on route change
const url = 'https://static.scarf.sh/a.png?x-pxid=3c1d68de-8945-4e9f-873f-65320b6fabf7'
+ '&path=' + encodeURIComponent(location.pathname)
+ '&t=' + Date.now(); // cache-buster
// + '&machineType=' + machineType
// + '&appVersion=' + appVersion
// + '&licenseType=' + license
// + '&loginEnabled=' + loginEnabled;
console.log("ScarfPixel: reload " + location.pathname );
if (lastUrlSent.current !== url) {
lastUrlSent.current = url;
const img = new Image();
img.referrerPolicy = "no-referrer-when-downgrade"; // optional
img.src = url;
console.log("ScarfPixel: Fire to... " + location.pathname , url);
}
}, [location.pathname]);
return null; // Nothing visible in UI
}

View File

@ -8,6 +8,7 @@ import { BrowserRouter } from 'react-router-dom';
import App from './App';
import './i18n'; // Initialize i18next
import { PostHogProvider } from 'posthog-js/react';
import { ScarfPixel } from './components/ScarfPixel';
// Compute initial color scheme
function getInitialScheme(): 'light' | 'dark' {
@ -38,10 +39,10 @@ root.render(
debug: import.meta.env.MODE === 'development',
}}
>
<BrowserRouter>
<App />
</BrowserRouter>
<BrowserRouter>
<ScarfPixel />
<App />
</BrowserRouter>
</PostHogProvider>
</React.StrictMode>
);