Problem
The client package's visibilitychange listener (which calls collector.flush() on page unload) is gated on config.beaconUrl being set. If no beacon URL is configured, the listener is never registered and buffered/queued events are lost on navigation.
Core's flush() now drains the consent queue for permitted events (#5 / PR #12), but the client needs to actually call it on unload for this to matter.
Proposed Change
Register a pagehide listener unconditionally in the client that calls collector.flush(). The beacon-specific logic can remain gated on beaconUrl, but the basic flush should always happen.
// Always flush on page hide — ensures buffer and consent queue are drained
if (typeof document !== "undefined") {
const pagehideHandler = () => {
collector.flush();
};
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") pagehideHandler();
});
cleanupFns.push(() => document.removeEventListener("visibilitychange", ...));
}
Context
Follow-up from #5 (consent queue guardrails). Core-side flush() drain was implemented in PR #12, but the client doesn't always call it on unload. See also: agent-os/standards/core/consent-timing-heuristics.md (SPA vs MPA section).
Problem
The client package's
visibilitychangelistener (which callscollector.flush()on page unload) is gated onconfig.beaconUrlbeing set. If no beacon URL is configured, the listener is never registered and buffered/queued events are lost on navigation.Core's
flush()now drains the consent queue for permitted events (#5 / PR #12), but the client needs to actually call it on unload for this to matter.Proposed Change
Register a
pagehidelistener unconditionally in the client that callscollector.flush(). The beacon-specific logic can remain gated onbeaconUrl, but the basic flush should always happen.Context
Follow-up from #5 (consent queue guardrails). Core-side
flush()drain was implemented in PR #12, but the client doesn't always call it on unload. See also:agent-os/standards/core/consent-timing-heuristics.md(SPA vs MPA section).