Send a serialized analytics payload using navigator.sendBeacon.
navigator.sendBeacon
The endpoint URL that receives the beacon request.
Serialized event payload to send.
true if the user agent successfully queued the data for transfer, otherwise false.
true
false
This is intended for fire-and-forget flushing of analytics events during lifecycle transitions (e.g., page unload or visibility change).
const ok = beaconHandler('/analytics/batch', JSON.stringify(batchEvents))if (!ok) { // Optionally fall back to XHR/fetch} Copy
const ok = beaconHandler('/analytics/batch', JSON.stringify(batchEvents))if (!ok) { // Optionally fall back to XHR/fetch}
Send a serialized analytics payload using
navigator.sendBeacon.