A Server call using onUnload

Discussion in 'Javascript' started by shlomi.schwartz, Dec 22, 2005.

  1. 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
     
    shlomi.schwartz, Dec 22, 2005
    #1
    1. Advertisements

  2. shlomi.schwartz

    bwucke Guest

    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.
     
    bwucke, Dec 22, 2005
    #2
    1. Advertisements

  3. shlomi.schwartz

    Jonas Raoni Guest

    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 :)
     
    Jonas Raoni, Dec 22, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.