Last updated

flushEventsWithBeacon()

Sends pending events using the Beacon API. Best for page unload scenarios.

Signature

await window.FairShareSDK.flushEventsWithBeacon();

Why Use Beacon?

The Beacon API guarantees delivery even when the page is closing. Regular fetch requests may be cancelled when navigating away.

Example

// Flush events before page unload
window.addEventListener("beforeunload", () => {
  window.FairShareSDK.flushEventsWithBeacon();
});

Visibility Change Pattern

A more reliable pattern for mobile browsers:

window.addEventListener("visibilitychange", () => {
  if (document.visibilityState === "hidden") {
    window.FairShareSDK.flushEventsWithBeacon();
  }
});