SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast rajasreekm's Avatar
    Join Date
    Sep 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page visit Duration

    I want to calculate time the visitor stay on each page visit ....Not using google analytics....Using ajax,PHP and jquery

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP can record the date/time the page was served to a specific IP address, by storing the data in a database table.

    Then there are two options to record the date/time that page was left ...

    1. Use an onunload event to run some javascript (AJAX) code to call a PHP file to store the date/time - this depends on the user allowing JS to run.

    2. In each PHP page check the HTTP_REFERER header; if it's value is from your domain then use that to record the date/time of the previous page - this would only work whilst navigating within your site; once the user leaves your site then the last-visited page would never have a "left" date/time record.

    Option 1 is neater but not guaranteed to work. Option 2 will almost always work except for when the user leaves your site.

    I'm sure there may be other options - I'll leave that for others to propose.
    Ian Anderson
    www.siteguru.co.uk


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
  •