flushEvents()
Sends all pending events to the server.
Signature
await window.FairShareSDK.flushEvents(sync?);
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
sync | boolean | true | Wait for events to complete (sync) or return immediately (async) |
Examples
Sync Flush (default)
// Wait for events to be sent await window.FairShareSDK.flushEvents();
Async Flush
// Don't wait, return immediately window.FairShareSDK.flushEvents(false);
Use Cases
- Before navigation in single-page apps
- After critical user actions
- When you need to ensure events are sent
SPA Navigation Example
// React Router example useEffect(() => { return () => { window.FairShareSDK.flushEvents(); }; }, [location]);
Related
- flushEventsWithBeacon — Flush on page unload
- trackFairshareEvent — Track events