2

this question is different to this one, which detect if a browser is currently active.

I would like to detect more types of user behaviors, thing like

  • read throughout the article from beginning to the end very quickly
  • read throughout the article from beginning to the end slowly
  • Read a few lines and leave
  • search a keyword inside the article and read the part contains that keyword
  • You can't really know what the user is or isn't reading. So, while you may be able to derive some signals based on visibility of content, time on page, and scrolling, keep in mind the limitations. It's pretty common for users to have multiple windows up simultaneously. Very large screen resolutions are not uncommon, as are oddball zoom levels. There is also the case of opening a window and then getting up to get coffee and making it look like time-on-page is 15 minutes. – Brad Jul 15 '19 at 02:49

1 Answers1

1

These are most likely to be done using Intervals and a little bit of window screen height. For example, if the user scrolls down, you can get the value of their screen's Y-axis then trigger a new Time class, then as soon as the user reached the bottom of the page. Stop the timer and get the value through AJAX and save it to your database.

For example:

window.onscroll = function() {
     if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
       var time = setInterval(savetimeEverySecond(), 1000);
     }
     if($(window).scrollTop() + $(window).height() == $(document).height()) {
       //clearInterval()
       //I have reached bikini bottom, might as well do my ajax
     }
};
Bernard P.
  • 21
  • 1
  • 4