About This Script
Add this to your site by copying and pasting the code (below) to where you would like it to appear on your page. You need to add this to every page you would like to count towards the total time a user spends on your site.Code
<!-- jQuery is required if you're not already using it -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
(function(){
var previousCookie = $.cookie('timeOnSite');
var timeOnSite = previousCookie ? parseInt(previousCookie) : 0;
function incremementTimeOnSite() {
++timeOnSite;
showTimeOnSite();
$.cookie('timeOnSite', timeOnSite);
}
function showTimeOnSite() {
var hours = (timeOnSite / 3600) % 24;
var minutes = (timeOnSite / 60) % 60;
var seconds = timeOnSite % 60;
var str = '';
if (hours >= 1) {
str += Math.floor(hours) + ' hour' + s(hours) + ' ';
}
if (minutes >= 1) {
str += Math.floor(minutes) + ' minute' + s(minutes) + ' ';
}
str += seconds + ' second' + s(seconds) + ' ';
$('.timeOnSite').html("You've been on our site for " + str);
}
function s(num) {
if (num >= 2) {
return 's';
}
return '';
}
setInterval(incremementTimeOnSite, 1000);
})();
</script>
<noscript>Time on site provided by <a href="http://www.top-site-list.com">Top Site List Planet</a></noscript>
<span class="timeOnSite"></span>
More scripts