Files
robertseares/frontend/app/PageLoadTracker.jsx
a2a-platform 1a1e8db145 deploy
2026-06-13 11:20:08 +00:00

39 lines
958 B
JavaScript

"use client";
import { useEffect } from "react";
export function PageLoadTracker({ locale }) {
useEffect(() => {
const payload = {
path: window.location.pathname,
locale,
referrer: document.referrer || null,
viewport: {
width: window.innerWidth,
height: window.innerHeight,
devicePixelRatio: window.devicePixelRatio || 1,
},
metadata: {
language: navigator.language || null,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || null,
},
};
const body = JSON.stringify(payload);
if (navigator.sendBeacon) {
const blob = new Blob([body], { type: "application/json" });
navigator.sendBeacon("/api/page-load", blob);
return;
}
fetch("/api/page-load", {
method: "POST",
headers: { "content-type": "application/json" },
body,
keepalive: true,
}).catch(() => {});
}, [locale]);
return null;
}