This quick snippet of jQuery that will allow you to so do something before the user navigates away from a page or closes the browser or tab.
In this example I have mixed in some JavaScript Date functionality to give a timer of how long you were on the page.