My goal is to track how many consecutive daily visits users make each week to my site using cookies. So far I have created this code that sets the cookie expiration to the next Sunday.
<script>
(function(){
var cookieName = "Weekly access";
var cookieValue = "1";
var nextSaturday = new Date();
nextSaturday.setDate(nextSaturday.getDate() + (7 + 7 - nextSaturday.getDay()) % 7);
document.cookie = cookieName+"="+cookieValue+"; SameSite=None; Secure;
expires="+nextSaturday+"; path=/; domain=." + location.hostname.replace(/^www\./i, "");
})();
</script>
However, I would like to change the value of the cookie in case a new visit occurs the next day:
- one visit per week = value 1
- two consecutive visits = value 2
- three consecutive visits = value 3
- .....
How can I do this?