const payload = {
  eventType: "page_view",
  pagePath: window.location.pathname || "/"
};

const body = JSON.stringify(payload);
const url = "/api/track";

try {
  if (navigator.sendBeacon) {
    const blob = new Blob([body], { type: "application/json" });
    navigator.sendBeacon(url, blob);
  } else {
    fetch(url, {
      method: "POST",
      headers: {
        "content-type": "application/json"
      },
      body,
      keepalive: true
    }).catch(() => {});
  }
} catch (error) {
  // Ignore analytics errors on the public page.
}
