yad4u ASP.NET MVC - Detect Time Spent on Page

ASP.NET MVC - Detect Time Spent on Page

Does anyone know of a way to save to capture and save the amount of time spent on a page in ASP.NET MVC?

Edit To clarify a few points:

  1. Essentially the system is concerned with product placement. I am tracking the # of views of a particular product. However, to take it further I would like to see on average how long customers stay on a particular product page
  2. I would like to save and store the data locally so that I can trend and analyze it along with other data currently captured - i'd like to avoid external services wherever possible.
  3. My main concern is with trapping an event on page load and again on exit - this is obviously difficult a) because ASP.NET MVC doesn't have as rich/fancy an event pipeline as vanilla ASP.NET and b) it is possible that a user will close the browser/navigate to a different site thereby complicating matters a little.

Thanks in advance, JP

Using a .NET MVC Controller Action as the Source for an HTML <img>


ASP.NET MVC: How do I validate a model wrapped in a ViewModel?
I've done this two ways in the past.
ASP.NET MVC Rich Text Editor not showing buttons
Is there a template language for ASP.NET MVC like JSTL and OGNL?
Read your iis logs, look at the times between the request for one.html and two.html from the same user.
Selling upper management on converting to ASP.NET from Classic ASP
Membership provider stopped working on using Membership Provider in ASP.Net MVC
javascript counter and onunload function which sends an ajax call to some service that logs the time.
Design decisions

ASP.NET Exception Handling in background threads


It depends, you could use javascript to track the time and display it on the page.. If's required on the server and it's on a form that posts, you could put the time into a hidden field, then on post you could extract the value and calculate the difference.

. You could try storing it in a cookie.

Each time a user requests a new page, you could extract the page title and the timestamp, and then set the cookie with a new page and timestamp.. You could also use some sort of Business Intelligence suite.

Such as Omniture or Google Analytics .


I guess you could have an ajax function that calls home every x seconds or minutes with a small package just the sessionId and page/url, on the server side it would know to add x time to the proper structure structure.

. Another way could be to have a hidden field that has the creation time stamp of the page, and then intercept the page is changed/closed/nav.

away, and then call home with the time difference (or the 2 values and do the calc server side) and the the page/url...

but I think you could risk not getting the info if the browsers suddenly crashes, or the call is lost and the page already changed.. just some suggestions.

59 out of 100 based on 34 user ratings 1159 reviews