Debt Consolidation - Just Holden Commodores - Wordpress Themes - Creative Electronics - Free Animated Greetings

PDA

View Full Version : Record visitor's time on a webpage


weknowtheworld
Apr 18th 2007, 10:53 am
Hi there,

How do you record how long a visitor has been viewing a webpage?

Thanks for replying.. :)

ajsa52
Apr 18th 2007, 12:55 pm
I don't record that by myself, instead I'm using Google Analytics who provides that and many many more useful info
.

krakjoe
Apr 19th 2007, 2:30 am
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
var seconds = null;
function timer( )
{
seconds++;
setTimeout( 'timer()', 1000 );
}
function tellUser( )
{
alert( 'Thanks for visiting, you viewed this page ' + seconds + ' seconds' );
}
</script>
</head>

<body onunload="tellUser();">

<script language="javascript">window.onload=timer();</script>
</body>
</html>


You could do it like that, only instead of alerts use ajax and php to update a database or write to a file

weknowtheworld
Apr 19th 2007, 4:10 am
Thanks krakjoe for such kind help... :)