******Cookies.set("recently_viewed",'[1]' , 3, "/");*********
var productIDArray = JSON.parse(Cookies.get("recently_viewed"))
if(productIDArray == null) productIDArray = [];
productID = window.location.href.split("product_view/")[1].split("/")[0]
// alert(productID)
if (productIDArray.length < 7){
if (productIDArray.indexOf(productID) === -1) {
productIDArray.unshift(productID);
}
}
else{
if (productIDArray.indexOf(productID) === -1) {
productIDArray.pop(productID);
productIDArray.unshift(productID);
}
}
Cookies.set("recently_viewed", JSON.stringify(productIDArray), 3, "/");
So Im trying to execute this script which appends the product id from url to the cookie named recently_viewed. By default this cookie doesnt exist, so im being forced to use the first line which i enclosed in ***
But that keeps resetting the cookie value everytime i reload the page.
Is there any efficient way to do this?
Thanks in advance