In jQuery we can check when users start interacting with a web page.
We can keep track of the first mouse movement after a page is fully loaded by memorizing the exact time when such event occurs.
$(function() {
sessionStorage.setItem( "start", Date.now() );
$( "body" ).one( "mousemove", function() {
var elapsedTime = Date.now() - parseInt( sessionStorage.getItem( "start" ), 10 );
$.post( "/api/stats/users/interaction", { time: elapsedTime, page: location.href }, function( response ) {
sessionStorage.removeItem( "start" );
});
});
});