I like to measure the time a user spent on a particualr page of my webapp. First i thought about catching the onunload/onbeforeunload event in the browser and notify the server via a XMLHttpRequest that the user is leaving now like:
<body onunload="userLeaves('/url/to/current/page',xxx);" ...> ... </body>
where xxx is the inital tiemstamp when the page was rendered.
Unfortunately this solution doesnt work in all browser (e.g. Opera). So my second idea was to ping the server constantly. To calculate the visiting time someone has to take the last ping time and subtract it from the inital timestamp. But i dont think thats a good solution either especially when a user has opend 3 or 5 tabs and every tab is firing events every 500 ms ...
how would you measure the visiting time? has someone a better idea to obtain the time spent on one particualr page?