Forum Moderators: open

Message Too Old, No Replies

How to get the timespan a visitor stays on site before bouncing away?

         

ichsie

9:02 am on Apr 29, 2008 (gmt 0)

10+ Year Member



Trying to build a cute little php site statistics script, now I'm stuck with getting the average visiting time on site.

How to do that? I'm using JS badge.

HTTP is stateless, if that is the case how the server knows when the visitor navigates away? JS onunload?

httpwebwitch

12:22 am on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yup - onunload will do it.

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

trader

1:41 am on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Google Analytics does a nice easy to read display of the bounce rate on the front page of stats.

However, I only use Analytics on just 1 site. I don't see how to get the bounce rate using stats programs such as AWstats (which I use heavily), or other reports from my server.

JAB Creations

8:02 am on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Keep in mind that you shouldn't rely too heavily on the time spent on any particular page. Some people may leave your page open in the tab/window and walk away to take care of a non-computer issue. They may come back and turn off the computer before they go out or if a thunderstorm is approaching. I have also known web developers who literally have a hundred open tabs at any time. I do personally use Firefox's "last session's tabs/windows" option. So don't beat yourself over weird statistics but at the same time don't take this as me saying that you shouldn't do it; I really really dislike people who pull that on threads I start. Any way good luck ichsie!

- John

ichsie

1:44 pm on Apr 30, 2008 (gmt 0)

10+ Year Member



Thank you everyone, I somehow came up with a solution.

Agree with you JAB, I'm not going to make it for site stats. =)