2 ms·
This works as long as the user is navigating around inside your site - but it won't work if the user e.g. navigates to a different domain or closes the browser
by xg15 5y ago
This works as long as the user is navigating around inside your site - but it won't work if the user e.g. navigates to a different domain or closes the browser window.
If you specifically want to track when a user leaves a page, you will miss a lot of events this way.
- maccard 5y agoWhat's the difference between leaving a page and leaving the tab hanging open in the background for a week?
- xg15 5y agoOne is done more often than the other. Of course there is no way to perfectly, reliably capture 100% of the events. Even if browsers had a dedicated API for that, a user could simply kill the process or pull the plug. However, you can make sure you capture the vast majority of events. Clicking on a link or closing a tab are much more likely events than killing the browser or leaving a tab open for weeks. (On desktop at least, might be different for mobile. But even there, you might want to track how many pages just stay open forever - which would also require you to track close events.)