javascript - Calculate total time user has done activities on page like mousemove in jquery -
please me. have find total time user has done activities on page mousemove, keypress etc. want useful time page has been used. have made of code calculates total time page has been opened , time user has focused in page.
an other approach calculate useful time can calculating total idle time on page, nothing (i mean mousemove, keypress) has been done. useful time = total page opening time - total idle time
please here code.
var start, end, openingtime, pagefocustime = 0; $(document).ready(function(){ start = performance.now(); $(window).on('blur', function() { end = performance.now(); pagefocustime += end - start }) $(window).on('focus', function() { start = performance.now(); }) $(window).on('beforeunload',function(){ end = performance.now(); pagefocustime += end - start console.log("exact page focused time : "); console.log(pagefocustime); openingtime = end-start; console.log("total page read time : "+ openingtime); }); });
please help. in advance.
here answer. use code above code.
function setup() { this.addeventlistener("mousemove", resettimer, false); this.addeventlistener("mousedown", resettimer, false); this.addeventlistener("keypress", resettimer, false); this.addeventlistener("dommousescroll", resettimer, false); this.addeventlistener("mousewheel", resettimer, false); this.addeventlistener("touchmove", resettimer, false); this.addeventlistener("mspointermove", resettimer, false); starttimer(); } setup(); function starttimer() { timeoutid = window.settimeout(goinactive, 10000); } function resettimer(e) { window.cleartimeout(timeoutid); goactive(); } function goinactive() { idletime = idletime + inactivetime; } function goactive() { starttimer(); }
Comments
Post a Comment