Jump to content

Track Time Spent Viewing a Page


thesaleboat

Recommended Posts

Can someone point me in the right direction or give me some guidance as to how to track time that a user spends viewing a page.  The database is already set up and I already have a ton of interaction between php and mysql on the pages. Just wondering if there is a way to tell when the user first views the page and then leaves, and if he comes back continue to add that time to that page.  Every page is numbered if that helps at all e.g.

<?php
session_start();
$subcategory = 612;
?>

Any help is greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/
Share on other sites

You could get this information from your access logs, or the way I implement this is to use a tracking session or cookie.

 

Have a session that records the page a user is on.

$_SERVER['PHP_SELF'];

When a page is accessed the session will store the time

time();

that the page was requested. When the user then clicks to another page again the session records the request time therefore allowing you to calculate the time difference between requests which is the total time the user spent on the page. You can save this information to a database and even track a users path throughout your site. This is useful for testing the quality of your pages that may lead to a sale if you have an e-commerce site. For instance most sales are made when a user clicks on page x as the next request they make is the payment page, but users tend to leave the site when they reach page y, etc..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.