Navigator.sendBeacon() doesn't send ping on mobile devices when browser tab is closed/tab switched/app closed #17978
Labels
Bug
For errors / faults / flaws / inconsistencies etc.
duplicate
For issues that already existed in our issue tracker and were reported previously.
Help wanted
Beginner friendly issues or issues where we'd highly appreciate community's help and involvement.
Expected Behavior
When using
_paq.push(['alwaysUseSendBeacon']);
we would expect to be able to track an accurate time on page for all devices.(This is already enabled by default, but even when defining a lower time for the sendBeacon such as a few seconds doesn't change the behaviour)
Current Behavior
Currently this seems to work for desktop browsers. However, mobile devices seem to not send a ping request when the tab is closed, the tab is switched or when switching to a different app on the mobile devices.
This causes inaccurate time on page metrics for all mobile devices for the last page in the visit as well as inaccurate visit lengths when a visitor only views a single page.
Possible Solution
I don't know the exact method that is currently being used for the sendBeacon, but the Mozilla docs: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon recommend to use
visibilitychange
event instead ofunload
orbeforeunload
https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilitychange_event
Your Environment
The text was updated successfully, but these errors were encountered: