Skip to content Skip to sidebar Skip to footer

Detect User Exit Site

I have an urge to detect when a user leaves my site in order to record accurately the session length of the user in question. I have thought of a couple possible solutions for this

Solution 1:

You could poll using Javascript. For instance if you have a ticker text or image scroller that loads new information using Ajax, you can use the times of those requests to guess the last activity. You could also do dedicated requests for it, but to the visitor that is a waste of bandwidth, and they might not like the idea of such strict monitoring.

You could also measure times between page views, and leave the last page view (the exit-page) out of the equasion.

Solution 2:

You can't tell when a user leaves your site, this is fundamentally unsupported by the underlying technology of the Internet. All you can do is tell the time of the last request made before the session expired.

Solution 3:

If you need to do this for specific users then the best bet is to do an Ajax request, say, every 60 seconds, and record the timestamp against their session in your database. When you're measuring the responses you can classify anything beyond a reasonable cut-off as having 'left' (for example 20 minutes for a typical browser session).

If you don't need this data for individual users and just want an average metric for your visitors, you may as well just use Google Analytics.

Post a Comment for "Detect User Exit Site"