Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: Tracking Page Views and view Duration

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?

like image 289
LiamGu Avatar asked Feb 03 '26 05:02

LiamGu


1 Answers

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

window.onbeforeunload = function() { //do ajax call }
like image 99
John Farrell Avatar answered Feb 05 '26 22:02

John Farrell