I use this function with cache to make if the user enter the site for first time in last x minutes redirect him and if this is the second time press the button i now want to add if this is the third time in last x minutes to do another thing.
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(";").shift();
}
function setLastAccess() {
const date = new Date();
const expireMs = 0.5 * 60 * 1000; // number of minutes
date.setTime(date.getTime() + expireMs);
document.cookie = `lastAccess=${new Date().getTime()};expires=${date.toUTCString()};path=/`;
}
if (!getCookie('lastAccess')) {
window.location.href = "http://google.com";
setLastAccess(); // set your last access at the end
} else {
setTimeout(function() {
document.getElementById('button-login').click();
}, 1000);
}