views:

74

answers:

1

I have an application I'm currently working on that requires Administrators to be able to track the views of a ticket and it's duration.

I've got the tracking of the number of views by users sorted out, I have a table that contains a TicketID, UserID and a DateOpened. Each time a user visits the page, a new row will be inserted.

However, the way I would like to track the duration of views is by having a DateClosed field in the table which will allow me to work out view duration in the code as opposed to storing the time directly.

I can't use Google Analytics or anything Third Party for the task either due to internal policy as it's an intranet application.

What would be the best way to achieve filling this field on page exit?

+6  A: 

Before the window "unloads" simply make an AJAX call.

window.onbeforeunload = function() { //do ajax call }
jfar