I\'m looking to track users average time on a website (in the same way that Google analytics does) for internal administration.
What\'s the easiest way to do this?
$(window).unload is a very good function to tracking user leaving page.
but one point is when window unload to send ajax sometime it now work, the ajax not finished when user leave page. so you need add one attribute (async: false) to ajax, code is blow:
$.ajax({
type: 'POST',
async: false,
url: '/collect-user-time/ajax-backend.php',
data: {time: time}
});