The site will fire toggleOffersActivation() which shows a popup off a number of different triggers (like scroll distance, mouse out of window, etc).
toggleOffersActivation() also sets the cookie "modal=seen" if not already set. This cookie should expire after 24 hours.
The triggers should only fire toggleOfferActivation() if this cookie is not set.
Here's toggleOffersActivation() :
function toggleOffersActivation(){
loremOffers.classList.toggle('activatedOffers');
if(document.cookie.includes("modal=seen") == false){
document.cookie='modal=seen; max-age=86400; path=/; domain=lorem.com';
document.cookie='modal=seen; max-age=86400; path=/; domain=shopifypreview.com';
document.cookie='modal=seen; max-age=86400; path=/; domain=myshopify.com';
}
}
However, this is not the case, after a random amount of time before the 24hr expiry happens, toggleOffersActivation() will fire as if the cookie wasn't set.
Heres an example of a block of code that would trigger the function:
if(document.cookie.includes("modal=seen") == false){
var scrollTimeout;
window.addEventListener('scroll', function(){
if(scrollTimeout){
window.cancelAnimationFrame(scrollTimeout);
};
scrollTimeout = window.requestAnimationFrame(function(){
if(window.scrollY > 800 && document.cookie.includes("modal=seen") == false){
toggleOffersActivation();
ga("send", "event", "Website Popup", "Trigger", "Scroll Depth");
}
})
})
};
this will Check if the cookie is set, and if not, will create an eventListener that will fire the toggleOffersActivation() function if the user scrolls more than 800px. you can ignore the Google Analytics ga() function.
Why does my pop-up appear again, before 24hours has elapsed??