/    Sign up×
Community /Pin to ProfileBookmark

calculate site viewing time

hi all,

how to calculate the total site viewing time and How much time he spent on each individual page using javascript or php.

can any one please help me
thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@GenixdeaeMay 31.2008 — To get the overall site generation, put $start_time at the top of your page(first thing to run), and then put the $end_time at the bottom(last thing run. then just subtract your start_time from your end and you have your page generation time.[code=php]//Start time
$start_time = microtime();

//End time
$end_time = microtime() - $start_time;
$end_time = round($end_time, 5);
echo $end_time;[/code]

For the total, depending on if you're wanting stats or user visit time will depend on how you calculate the total. If you're looking for the stats then just make another variable like $site_time and keep adding to that after each page is made.[code=php]$site_time += $end_time //might be =+ can't remember
echo $site_time[/code]


hope that helps get you started
Copy linkTweet thisAlerts:
@mvnr_83authorMay 31.2008 — Thanks Genixdeae for ur replay.

but my requirement is calculate page visit time of a particular user and post that time in the database. i am thought less if user terminate from that page.

can u please help me regarding this
×

Success!

Help @mvnr_83 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...