Is there a way to track the number of times a user visits a page, but only increment the visit count if more than 30 minutes have passed since their last visit?
If so, how can this be accomplished?
Currently, I am using the following code snippet to set and get the cookie:
getCookie('xVisitors');
setCookie('xVisitors', 1, 120);
function setCookie(name, value, expiry) {
var expires = "";
if (expiry > 0) {
var date = new Date();
date.setTime(date.getTime() + expiry * 60 * 1000);
expires = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + value + expires + "; path=/;";
};
function getCookie(name) {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
while (cookie.charAt(0) == " ") {
cookie = cookie.substring(1);
}
if (cookie.indexOf(name) == 0) {
return cookie.substring(name.length + 1, cookie.length);
}
}
return "";
}