As part of a website I am building for work, one of the requirements is to have some statistics.

I would like to do this:

  1. Know what words were used on a search engine - if that's how they found the site
  2. Know how long they spent in total on the website
  3. Perhaps also know which products they viewed (probably similar to number 2)

I'm really unsure how this could be done. I have a feeling sessions would be required, but I am really unsure how to tell when the user has left the page.

Any ideas?

    Why not just get Webalyser (I think that is how its spelled)?

      Well it's for work. It is for one of our clients. Plus I want to try and do it myself, as it will be a lot easier to maintain, change, update, etc.....

        All that info is contained in the Apache log. Just make a PHP script to run through the Apache log and extract it.

        Scripts like this normally cause disappointment as the client realises that they don't get any web traffic.

          bokehman wrote:

          All that info is contained in the Apache log. Just make a PHP script to run through the Apache log and extract it.

          Scripts like this normally cause disappointment as the client realises that they don't get any web traffic.

          Thanks, although most servers (including the one I am working on) does not allow reading of the access.log unless root.

          I wouldn't mind changing the permissions but it is for a client of ours, and don't really want to tell them to start fiddling around with permissions.

          Can this not be done with sessions? Start a session when they visit. The only problem I can see is how you know when they have left your website. Suggestions please?

            redrabbit wrote:

            Thanks, although most servers (including the one I am working on) does not allow reading of the access.log unless root.

            I've never heard of that before. Most hosting plans I have seen put the apache log in /public_html/../logs/. Obviously if they are running dynamic virtual hosts things are different because the log needs to be run into a FIFO if set up properly. But I run my own server now so I can set things as I please.

            There of no way, using a standard request to know when someone closes your page but using the XMLHttpRequest object it would be possible to send a request to the server every n seconds to confirm they are still viewing. Of course server load would be increased.

              Write a Reply...