In web applications, there are times when you may want to track activity of a user within your page – perhaps your project includes a realtime component that you want to pause when the user isn’t actually working with the page, for example. This is pretty easy to take care of, but there are a few little quirks, so to simplify it all I’ve released a MooTools class to take care of it for you.
The class is super simple to use, all that is required is for it to be instantiated and it’ll get on with it. You can specify how many seconds of no activity on your page before the user is classed as idle, as well as a couple of more technical options, then just attach a function to the onIdle and onIdleReturn events of the class. For example:
-
var tracker = new IdleTracker({
-
idleTime: 2,
-
onIdle: function() {
-
// User is idle
-
},
-
onIdleReturn: function() {
-
// User has returned
-
}
-
});
You can get full details and download the class from my GitHub account.