Forum Moderators: open
onload, set a variable to the current time in milliseconds.
onunload, subtract that var from the current time, and send the result to your server using an XHR.
If you want to track that user across multiple pages, use a cookie or a session.
Another way to do it without onunload is to have the page ping you every 5 seconds on a timer, again using XHR or a pixel bug. When the pings stop, your page view hath ended. I wouldn't recommend that technique on a busy site.
pixel bug = you put an invisible hotlinked 1x1 image on the page, and get Javascript to change its src every few seconds
- John