// Inlined by PageViewBeacon.beacon_script; the page passes the endpoint and token.
(function () {
const { endpoint, token } = document.currentScript.dataset;
// Automated browsers (Selenium, Puppeteer, Playwright) aren't visitors.
if (navigator.webdriver) return;
function send() {
try {
fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ t: token, r: document.referrer }),
credentials: "same-origin",
keepalive: true,
});
} catch {
// The view is lost; never break the page over it.
}
}
// Counted on load like GA, which also holds a prerender until it is shown.
if (document.prerendering) {
document.addEventListener("prerenderingchange", send, { once: true });
} else {
send();
}
})();