An exit event is a best-effort send
A visitor clicks a button and immediately leaves. Will the analytics event arrive? Sometimes—but a browser page closing is not a reliable place to create or guarantee a business conversion. WhoVisited tries to flush its in-memory queue on `pagehide`, and its event request uses `fetch()` with `keepalive: true`. That lets an already-started request continue after the document is unloaded in supporting browsers. It does not turn the browser into a durable queue or prove that the server accepted the event.
For signup, payment, or booking outcomes, send the analytics signal when the application knows the outcome succeeded. Use your database or payment provider as the source of truth; analytics is a report of browser activity, not a transaction ledger.
The current WhoVisited send path
The tracker puts events in a JavaScript array in memory. Calling `window.whovisited.track()` asks it to flush, and a timer tries again every two seconds. When the document receives `pagehide`, the tracker also calls the same flush function. Before it can post events, the tracker may need a bootstrap request to obtain a short-lived ingestion token. That bootstrap `fetch()` does not set `keepalive`; only the later `/api/v1/events` request does.
This detail matters on a first, very short visit. If the page is left while the bootstrap request is still pending, the event POST has not started yet. A `pagehide` flush sees that another flush is already in progress and returns. The browser may cancel the unfinished bootstrap as the document goes away, so the queued event can disappear with the page. Once bootstrap has completed on the current page, an events POST can start immediately and `keepalive` gives that request a better chance to finish.
Each request contains at most 20 events and the tracker caps the serialized batch at 30,000 bytes. If several events have accumulated while another send is in flight, the pagehide call does not start a second request. Remaining events stay only in that page's memory until another timer-driven flush happens; if the page is discarded first, that queue is gone.
Keepalive is not an acknowledgement
The Fetch API's `keepalive` option tells the browser it may keep a request alive after the initiating page unloads. It does not promise delivery through a lost connection, browser shutdown, an extension blocker, a rejected consent state, an origin or token error, a rate limit, or an ingestion quota. The request may still fail, and the page may be gone before application code can react to its response.
There are size limits too. MDN documents a 64 KiB body limit for keepalive requests. WhoVisited's current 30,000-byte batch cap is lower than that individual limit, but the browser can also account for other outstanding keepalive requests. A small body is not the same as guaranteed acceptance. In this implementation, the events endpoint responds with HTTP 202 when it accepts the batch; that response is useful evidence when visible in Network, but it is not available if the browser never starts or completes the request.
Test the journey, not just the script tag
- Use a test website and a fixed, non-personal event name such as `exit_delivery_check`. Confirm the tracker has loaded, the website and origin are configured, and consent permits collection and custom events are enabled for the site.
- Open DevTools Network before the test. Keep the log across navigation, filter for `/api/v1/bootstrap` and `/api/v1/events`, and note which request is pending when you leave.
- First run a baseline: load a page, wait for the bootstrap to finish, trigger one test event, stay for a moment, and confirm that the events request receives 202.
- Then repeat on a fresh browser session and navigate away immediately after triggering the test event. Compare whether bootstrap had completed and whether an events POST actually started. A script request returning 200 alone does not prove event ingestion.
- Wait for the dashboard or test-event view to update, then repeat with consent denied or the browser offline as a negative control. Do not use a real signup or payment to test this path.
The test distinguishes three separate states: the script loaded, the browser attempted a request, and the server accepted an event. Only the last is evidence that the event was ingested. Results can vary with browser lifecycle, network timing, consent, extensions, and whether the bootstrap token was already available.
Record a conversion at the success point
Do not rely on `pagehide`, `beforeunload`, or a tab-closing handler to decide that a signup, purchase, or booking happened. A click may lead to validation errors, an abandoned checkout, a blocked popup, or a failed payment. Record the custom event in the application flow that confirms success, and let normal tracking begin sending it while the page is active. For payments, verify success with the provider webhook or server-side state before showing or emitting a success signal.
If navigation follows immediately after a confirmed result, give the page a chance to start its normal request when your product flow allows it, but do not add an arbitrary delay that harms the user experience. Verify the accepted request in a controlled test. WhoVisited retries certain transient failures while the page remains alive, but its retry queue is in memory; it cannot replay events after a browser process is discarded.
Limits and references
This article describes the current browser tracker. Browser lifecycle behavior and request timing differ, and `pagehide` is not fired in every mobile app-switch or browser-close scenario. Keep exit flushing as a fallback, not the only path for an important measurement. See the MDN references for the keepalive request option and the `pagehide` event, plus the WhoVisited guides to ingestion retries and duplicate conversion events.
References and further reading
- MDN: RequestInit.keepalive and request body size limit
- MDN: Window.pagehide event
- MDN: Request.keepalive
- WhoVisited: diagnose HTTP 429 analytics ingestion responses
- WhoVisited: duplicate conversion events and retries
- WhoVisited: confirm checkout payments before analytics tracking
- WHATWG: Fetch Standard keepalive in-flight size quota