tags:

views:

121

answers:

2

I want to record time spent on webpages. Is there an appropriate JQuery plugin written for this? I could then record the value of the timer in a variable and insert to a database.

JJH

+1  A: 

Google Analytics is a great solution for this. A better, faster wheel has already been invented.

Diodeus
Yes,I have looked at this but it doesn't seem to offer a solution to identify logged in users of a website i.e. grab a userid and associate usage with this specific id. It seems to be more generalised. Maybe I'm wrong about this?
Ah, you didn't specify that you wanted to identify this at a user-level. Your web server's logs should already have this information. You need a decent reporting tool for your logs.
Diodeus
A: 

If you're hell bent on this feature it's quite easy:

var interVal = 60000; // 60 seconds (adjustable)
var totalTime = 0;
function LogTime() {
     totalTime += interVal;
     $.ajax { /* Your ajax call to tell the server totalTime */ }
     setTimeout("LogTime()", interVal);
}

setTimeout("LogTime()", interVal);

But Diodeus is probably right, there are better ways to get this metric.

Aren
Thanks. I might use this. I just need to do a crash course in Ajax.
@Aren B, why does the total time spent on the page include the interval?
Because you've waited interVal miliseconds on the page when LogTime() is called.
Aren