SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Track how long someone stays on a page

    I'm not sure if this is a PHP solution, a javascript solution or possibly both.

    The best way I've been able to come up with is to have a javascript timer that updates the server every 5 minutes or so using ajax. Is there a better way to do this?

  2. #2
    SitePoint Zealot twistie's Avatar
    Join Date
    May 2007
    Location
    Tonwsville, Australia
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think It'll have to be done user-side using javascript because PHP has no way of knowing what is going on with the page after it has completed rendering.

    I think your method should work but there may be an easier way. I'm not a JS wiz.
    "When you say 'I wrote a program that crashed Windows',
    people just stare at you blankly and say 'Hey, I got those
    with the system, for free'." (L. Torvalds)

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Manchester, UK
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Track how long someone stays on page

    Hi,

    If your using PHP a handy global variable from version 5.1.0 onwards is:

    $_SERVER['REQUEST_TIME']

    which returns the start time of the current request, and then grap a timestamp when the user leaves the page and compare the two?

    just a suggestion.

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Although I don't know exactly how to do this I know that Google Analytics support this as well as being a very powerful tool.

    http://analytics.google.com

    I recommend it

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hannson View Post
    Although I don't know exactly how to do this I know that Google Analytics support this as well as being a very powerful tool.

    http://analytics.google.com

    I recommend it
    And I recommend everyone put
    Code:
    127.0.0.1 google-analytics.com
    127.0.0.1 www.google-analytics.com
    Inside the host file located at C:\WINDOWS\system32\drivers\etc

    Yay no more slow page loads.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •