// Tells knotless-serve a page was drawn, for its operator's counts: the // route that drew it, and the site the visitor came from if another. Sent // once the page runs, so a crawler that reads the HTML alone sends none, // and never when the browser asks not to be followed (Global Privacy // Control). No cookie, and nothing about the visitor but what every // request carries. import type { afterNavigate } from '$app/navigation'; /** What `afterNavigate` hands its callback. */ type Navigated = Parameters[0]>[0]; export function hit({ to, type }: Navigated): void { const route = to?.route.id; const gpc = (navigator as Navigator & { globalPrivacyControl?: boolean }).globalPrivacyControl; if (!route || gpc) return; // Where the visitor came from counts only on arriving, from elsewhere. const from = type === 'enter' ? document.referrer : ''; const referrer = from && new URL(from).origin !== location.origin ? from : ''; navigator.sendBeacon('/_hit', JSON.stringify({ route, referrer })); }