Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way track the focus on tab with Javascript?

  • We need to track the EFFECTIVE time on site of our users
  • Most users, when they're done, leave the tab open and move to another tab
  • Time on site it's extremely inaccurate

Is there a Javascript Event to track the "loss of focus" of the current tab ?

like image 394
Leonardo Dario Perna Avatar asked Sep 05 '10 22:09

Leonardo Dario Perna


People also ask

How does my tablet detect focus?

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.


1 Answers

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.

like image 68
einarmagnus Avatar answered Nov 09 '22 03:11

einarmagnus