views:

49

answers:

5

I am building some custom logging code to track how people use our web application. I am doing this is in the Site.master page under ASP.NET MVC, but my question is actually more generic. What I would like to do is determine how long someone spends on a particular page.

I can track when people hit a certain page, but obviously I can't really tell how long they spend on a page through any server side code. What I am doing now is just calculating things this way:

Page A is hit at time T0 Page B is hit at time T1 therefore, someone most likely spent T1 -T0 time on page A.

Now, people can walk away from their computer, or whatever, so I have an arbitrary threshold of 120 seconds right now. If T1-T0 is > 120, then I just log a token that means "unknown"

This works, but seems pretty hack-y.

Does anyone have a better suggestion? I don't need code, just an algorithm.

+1  A: 

Unfortunately, they way you have described is pretty much the only way to do it, if you only have page-visit-times to work with.

However, if you can support a more "ajaxy" approach, you should feasibly be able to detect when the user is moving his mouse on your page, and so-on, and send little ping requests to a service URL.

That seems like a lot of work for very little return, tho.

John Gietzen
A: 

Using AJAX you would be able to send information to your server when interaction with the page occurs. This would give you greater accuracy on your times but it seems like it might be overkill.

Mervyn
A: 

You'll need to generate this from your log data and there will be assumptions built into it, as you've already noticed. Your deltas between recorded visits is the best data for visit time. Define the thresholds for your idea of a page visit (different from a site visit) then measure the deltas between hits, then you'll have your time-on-page. You should also take referrer into consideration. A referrer that matches the previous page it can be considered a page visit and a valid time delta. A referrer form a different resource should not be considered a valid time delta for a page visit.

squillman
A: 

With Ajax, you can. Set a JavaScript timer for every 10 seconds or whatever, and then each time it hits zero, call a webservice method that will record the time last on the page for the user.

Ed B
A: 

Chartbeat does this for you in real time. Watching the data is terribly addictive, be warned.

Matt Sherman