If you want to implement this yourself, you need to decide when to get the start time--you can put a script tag at the top of the page, which may execute before the content has rendered, on the onload event, which will wait until all images and scripts have loaded, or something like the the JQuery ready event, which occurs when the DOM is ready, but doesn't wait for resources to load. At this point, you'd want to record a start time:
<script>var startTime = new Date().getTime();</script>
Then you can listen for the onunload or onbeforeunload event and use an image to send a GET request with the info:
<script>
window.onunload = function() {
var i = new Image();
var timeSpentMilliseconds = new Date().getTime() - startTime;
i.src = '/pagetime?timespent=' + timeSpentMilliseconds;
}
</script>
You'll have to do some testing to see whether the requests are always sent--I'm sure sometimes the browser closes or the tab switches before they finish firing.