thesaleboat Posted September 25, 2008 Share Posted September 25, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/ Share on other sites More sharing options...
JonnoTheDev Posted September 25, 2008 Share Posted September 25, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/#findComment-650716 Share on other sites More sharing options...
thesaleboat Posted September 25, 2008 Author Share Posted September 25, 2008 THanks neil, iM headin out for the day but Ill look into this tomorrow, anyone else have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/#findComment-650718 Share on other sites More sharing options...
JonnoTheDev Posted September 25, 2008 Share Posted September 25, 2008 You could also take a look at phpOpenTracker http://www.phpopentracker.de/ Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/#findComment-650722 Share on other sites More sharing options...
thesaleboat Posted September 26, 2008 Author Share Posted September 26, 2008 how do you get the time from time(); ? Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/#findComment-651288 Share on other sites More sharing options...
thesaleboat Posted September 26, 2008 Author Share Posted September 26, 2008 please ??? Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/#findComment-651321 Share on other sites More sharing options...
.josh Posted September 26, 2008 Share Posted September 26, 2008 You cannot reliably track how long someone has been viewing a page with php. You would need to use something clientside like javascript. Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/#findComment-651324 Share on other sites More sharing options...
thesaleboat Posted September 26, 2008 Author Share Posted September 26, 2008 That is exactly what i was looking for, thank you! Please tell me that there is someway to have javascript and php talk to each other... we already have a javascript clock on the top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/#findComment-651326 Share on other sites More sharing options...
.josh Posted September 26, 2008 Share Posted September 26, 2008 ajax. Quote Link to comment https://forums.phpfreaks.com/topic/125843-track-time-spent-viewing-a-page/#findComment-651328 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.