Newsletter modal + cookies

Hello,

I’m using a newsletter modal.

The code i’ve used clears cookies every 30 days so the user sees the modal again even if they have subscribed. Do you know how to store a cookie to hide the newsletter if the user has successfully subscribed so they don’t see the sign up again?

Here is the code i’m using i found here. I don’t have code knowledge so i’d appreciate any help.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script>
$(document).ready(function(){
  window.interval = 90 * 1000; // milliseconds.
  window.poll_interval = 5 * 1000; // milliseconds again
  var now = Date.now(); 

  function checkPopup() {
	var now = Date.now(); 
    console.log((90 - ((now - $.cookie('alert-timer')) / 1000 )) + "s till popup" );
 	if(!$.cookie('alerted')) {
	  	if ((now - $.cookie('alert-timer')) >= window.interval) {
	    	$('.popup-overlay').show();
	    	$.cookie('alerted', true, { expires: 30});
	    	clearInterval(window.poller);
	  	}
	  }
  }

  if (!$.cookie('alert-timer')) {
    $.cookie('alert-timer', now, { expires: 30 });
  }
  
  // Check every 3 seconds
  window.poller = setInterval(checkPopup, poll_interval);
});
</script>

Thank you


Here is my site Read-Only: LINK
(how to share your site Read-Only link)

Any code geniuses have an idea?

I’ve run into this issue before, its a regular problem. I’ve been using this:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js" ></script>
<script>
$(document).ready(function(){
if (!Cookies.get('alert')) {
 $('.popup-overlay').delay(8000).show(0);
 Cookies.set('alert', true, { expires: 28 });
}
});
// Documentation at https://github.com/js-cookie/js-cookie
</script>

The .popup-overlay class is the class name you need to tie into your Webflow styles.

Hope you found this helpful