Click to See Complete Forum and Search --> : Timed counter for .html and .pdf?


lemort
03-09-2009, 11:10 AM
Hi,

Is there a way to set a counter to count a visit only if it lasts at least certain time (lets say at least 15 min)?

I'm making a library web page where we want to set up an e-books section - some of the books will probably be in .pdf format and some in html - I'm afraid timing for .pdf is not possible? But also books in .html format consist of many addresses - for example the cover is index.html, the contents page index2.html and the all contents index3.html - so counting one IP-s visit/time on page will be difficult...

Any ideas?


Best,
lemort

TheBearMay
03-09-2009, 12:20 PM
If you load the pdf and other pages in an iframe you may be able to make it work. The example below uses the onbeforeunload event as a trigger, but you could use a straight setTimeout for 15 minutes if that works better for you:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var sTime=new Date();

window.onbeforeunload = function () {
var eTime=new Date();
alert ((eTime-sTime)/1000+ " seconds have elapsed");
}
</script>
</head>

<body>
<iframe src="file://path_to_File.pdf"></iframe>

</body>
</html>

lemort
03-09-2009, 01:50 PM
hmm I guess I was misunderstood... or I get it wrong myself.

TheBearMay, this code shows the visitor how long s/he was on the page, but i need it for statistics - for myself. I need to know how many visitors stayed on the page (reading a book, and even better, if knowing which e-book) for more than 15 minutes.

I do have Google Analytics set for the home page, but this means a new tracking code for every existing e-book, as far as I understand, which is too much when having tens of books on page and it does not show visitors who watched a certain page (e-book) for n minutes; it only gives average time on page.

TheBearMay
03-09-2009, 02:00 PM
Oh, I understood you, just didn't want to get too bogged down in setting up an AJAX call to a server side back end if the concept didn't work for you.

lemort
03-11-2009, 12:21 PM
Now when I actually think about, it might work.
I haven't found any counters that already do it :/

But is it able to leave me a log of visitors/visits (that have stayed for longer than 15 minutes) somewhere? I only know html, I have no experience in writing Ajax...

TheBearMay
03-11-2009, 12:55 PM
What do you have available on the back end language wise? Really just need something that can do a write to file or database on the server. Ajax wise something similar to the code below should work:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
var httpObject = null;
var oDest = null;
function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}

function setOutput(){
if(httpObject.readyState == 4){
document.getElementById(oDest).innerHTML = httpObject.responseText;
}
}


function callAJAX(serverProc, odest){
oDest=odest;
/* readyState
* 0 = uninitialized
* 1 = loading
* 2 = loaded
* 3 = interactive
* 4 = complete
*/
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("GET", serverProc, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput;
}
}

setTimeout ("callAJAX('UpdateLog.php?ebook=path_to_File&ipAddr=255.255.255.0','oPut')",900000);

</script>
</head>

<body>
<iframe src="file://path_to_File.pdf"></iframe>
<div id="oPut"></div>

</body>
</html>

Need to add some logic around getting the IP address of course (Server Side Includes or a server side language).