By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

A Server call using onUnload

P: n/a
Hi all,
I'm trying to create a server side log, that will show how much time a
user was present on my web page.

I tried using onUnload and onBeforeUnload to do an http call to the
server.
I've noticed that the call pass to the server is not consistent.

Q:Is there a better way of logging the time user spent on my page
before leaving it?

P.S: currently I'm using an Interval call each 5 sec that logs that the
user is still there.

thanks

Dec 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The call pass will never be consistent. The network/power on the user
side may go down, the user may close/kill the browser window, the user
may turn off javascript (especially if seeing the page calls home every
5s), the network may be slow enough that the call won't be forwarded
before the page is unloaded fully etc. There are things you simply
can't prevent.

An idea I have would be possibly a hidden frame that monitors the
webpage, survives the user following a link, reports the case the page
has been closed and then closes itself gracefully. Of course this
introduces a range of problems that would have to be adressed and some
that can't be addressed. Personally I doubt it can be done reliably
over HTTP.

Dec 22 '05 #2

P: n/a
You can make something using the idea of a chat where you have a
timeout solution...

When the user access your site for the first time (you can use the
session id or ip...), you can fill into the database the current
datetime and a timeout... And in *every* page call you should refresh
this timeout...
Whenever the user gets timed out (for example, after 1 hour of
inactivity), you could set the time he spent on your site...

Another way to do it, is by analyzing the web server log, there you can
check the first ocurrence of the ip on a certain date and make a diff
between it and the last ocurrence...

I would use a 3th party tool like awstats ;]

But if you want to do it on your own, it's ok, good luck :)
--
"Invente, Tente!!! Faça um código eficiente" (Jonas Raoni)

Jonas Raoni Soares Silva
---------------------------
jonasraoni at gmail dot com
http://www.jsfromhell.com

Dec 22 '05 #3

P: n/a
On 2005-12-22, sh*************@gmail.com <sh*************@gmail.com> wrote:
Hi all,
I'm trying to create a server side log, that will show how much time a
user was present on my web page.
If they save their page to their hard disk does that count as infinite time?

ISTM you are trying to measure the unmeasurable.
I tried using onUnload and onBeforeUnload to do an http call to the
server.
I've noticed that the call pass to the server is not consistent.
if they close the tab or turn off their modem there is no unload.

if they minimise the window, switch to another tab, or leave the room
are they still "present"
Q:Is there a better way of logging the time user spent on my page
before leaving it?
convince them to install your logging software on their PC :)
P.S: currently I'm using an Interval call each 5 sec that logs that the
user is still there.


it'll tell you the page is still open, nothing more.

Bye.
Jasen
Dec 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.