Is there a Javascript Event to track the "loss of focus" of the current tab ?
Use the visibilitychange event to detect if a browser tab has focus or not, e.g. document. addEventListener('visibilitychange', checkTabFocused) . The event is fired at the document when the contents of its tab have become visible or have been hidden. Here is the HTML for the examples in this article.
I would do something with mousemove
and scroll
and count a visitor as active as long as either of those trigger within some interval. That will also cover them leaving the browser open and leaving the computer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With