javascript - How to know how much time a user has our webpage open -


i'm trying guess how time user expend on website in php. that, thinking every new action on web, difference between $_server['request_time'] , current. planning stats of current hosting don't know if can these values via php request. point of view using first , second method, in advice should i'm not happy first option, cause server collapsed if amount of petitions high..., otherwise don't know other way if me, wonderful. on website i'm using html5, css3, php, javascript, jquery, ajax , mysql database. supposed i'd store , count time users stay logged in webpage. in advice.

there few ways of doing this, 1 way accurate readings.

php time difference

this method talking checking time difference. mark time user visited page. when visitor navigates page, subtract 2 times , have duration user looking @ previous page.

to make myself little more clear, below basic layout of actions need perform make php time difference method work.

  1. log current page url , time(). store cookie / session / entry in database.
  2. when user visits page, check http_referer variable , if matches page on, can calculate time on last page. referral check needed make sure not opening new tab , visiting site again. want add time limit if value on 30 minutes doesn't mark them visiting page on 30 minutes.
  3. keep repeating actions , have okay tracking method. won't specific , in cases not work if don't send referral header.

javascript tracking

you can send "heatbeat" or "ping" every few minutes tell server user still on specific page. want send url user on parameter, don't rely on http referral header sent. using method can accurate readings. track if user focused on web browser window or not check if page being read or in background.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -