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 p开发者_如何学JAVAoints:
- 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
- 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.
- 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
I've done this two ways in the past
1)
Read your iis logs, look at the times between the request for one.html and two.html from the same user
2)
javascript counter and onunload function which sends an ajax call to some service that logs the time
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
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
精彩评论