WebmasterID logoWebmasterID
Event tracking

Page visibility change events

A page-visibility event comes from the Page Visibility API's visibilitychange event, which fires when a tab becomes hidden or visible. Analytics uses it two ways: to pause engagement timing when a tab is backgrounded, and as the safest moment to flush pending events before a user leaves. It is a browser primitive that underpins reliable measurement, not a GA4 event you name yourself.

Verified against primary sources

What the API provides

The Page Visibility API exposes document.visibilityState and fires visibilitychange when it flips between 'visible' and 'hidden' (MDN). The hidden transition is the most reliable 'page is going away' signal across browsers — more dependable than unload — which is why it is recommended for final sends.

Why analytics relies on it

Engagement time should accrue only while the page is actually visible; pausing on hidden and resuming on visible keeps the figure honest. Separately, browsers may discard a backgrounded tab without firing unload, so flushing pending events on the hidden transition (often with sendBeacon) prevents silent data loss. Both uses are about accuracy, and both rely only on a coarse visible/hidden flag.

How it appears in analytics and logs

Engagement time that keeps climbing while a tab is backgrounded means the tracker is ignoring visibilitychange; lost end-of-visit events often mean it is not flushing on hidden.

Diagnostic use case

Stop counting engagement time while a tab is hidden, and flush queued events on the hidden transition so data is not lost when the user navigates away.

What WebmasterID can help detect

WebmasterID's tracker can use visibilitychange to bound engagement time and to reliably send queued first-party events before the page is discarded.

Common mistakes

Privacy and accuracy notes

visibilitychange exposes only a hidden/visible state, never identity. It is a timing primitive; keep any events you flush on it non-identifying.

Related pages

Sources and verification notes

Last reviewed 2026-06-24. Facts are checked against primary/official sources where available; uncertain specifics are marked “Data not yet verified” rather than guessed.