For those who are interested, I put some work into a small JavaScript library that increases the userβs interaction time with the web page. It has the added advantage of more accurately (not quite, though) tracking how long the user actually interacts with the page. It ignores the time when the user switches to different tabs, goes into standby mode, minimizes the browser, etc.
Edit: I updated the example to include current use of the API.
http://timemejs.com
An example of its use:
Include on your page:
<script src="http://timemejs.com/timeme.min.js"></script> <script type="text/javascript"> TimeMe.initialize({ currentPageName: "home-page", </script>
If you want to report time about yourself to your server:
xmlhttp=new XMLHttpRequest(); xmlhttp.open("POST","ENTER_URL_HERE",true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var timeSpentOnPage = TimeMe.getTimeOnCurrentPageInSeconds(); xmlhttp.send(timeSpentOnPage);
TimeMe.js also supports sending synchronization data via websockets, so you do not need to try to force a full HTTP request in the document.onbeforeunload event.
source share