Last active
July 3, 2021 08:38
-
-
Save Sheraff/b765113a8f6995b9608497e8e7e42f24 to your computer and use it in GitHub Desktop.
send GET request even if user leaves page w/ `sendBeacon`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// last reliably fired event before a user leaves | |
document.addEventListener('visibilitychange', () => { | |
if (document.visibilityState === 'hidden') { | |
// queues up a request to be sent even if the user leaves | |
navigator.sendBeacon('/log', analyticsData) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment