Skip to content

Instantly share code, notes, and snippets.

@ivarvong
Created March 27, 2015 21:19
Show Gist options
  • Save ivarvong/75c367f2e40ff040e331 to your computer and use it in GitHub Desktop.
Save ivarvong/75c367f2e40ff040e331 to your computer and use it in GitHub Desktop.
(function() {
var lastSeen = (new Date()).getTime();
var engagedTime = 0;
var idleTimeout = 5000;
$(document).ready(function() {
$(window).on('focus click scroll mousemove touchstart touchend touchcancel touchleave touchmove', function() {
lastSeen = (new Date()).getTime();
});
});
setInterval(function() {
var timeSinceLastEvent = (new Date()).getTime() - lastSeen;
if (timeSinceLastEvent < idleTimeout) {
engagedTime += 1;
}
}, 1000);
window.engagedTime = function() {
return engagedTime;
}
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment