MailChimp “Evil” Popup/Over Embed Code Doesn’t Set Cookies Properly

This post will probably only interest you if you use MailChimp to send enewsletters.

A few days ago I signed up for a MailChimp account so that I can publish enewsletters for my political humor website, PoliticLOLz. One of the features that they offer is an “evil popup mode.” Basically, the first time you visit a website, a box pops up that encourages you to sign up for the email newsletter. When you close the box, a cookie is set that tells the website that you’ve already visited and seen the box. This way, you won’t be bothered for a year or until you delete your cookies.

However, there is a slight problem with the code. If you’re having trouble with the box popping up more than once, you should change the following line in the code that MailChimp gives you.

Original:
document.cookie = 'MCEvilPopupClosed=yes;expires=' + expires_date.toGMTString();

Fixed:
document.cookie = 'MCEvilPopupClosed=yes;expires=' + expires_date.toGMTString() + ';path=/';

That should fix your problem. You don’t really need to know any more. However, if you’re curious as to how this works, read on.

Basically, when a cookie is set, it is given a particular path that defines the scope of the cookie, (i.e. which pages the cookie affects) and the path defaults to the path of the page being viewed. For example, if you visit http://yoursite.com/games/new, any cookies that are set will have a default path of /games/new, meaning that they will only be used on that page and its subpages (i.e. /games/new/top).

Of course, you can give a cookie a different path when you set it. Thus, by adding “ + ';path=/'” to the code, I am setting the cookie’s path to the site’s root, meaning that it will be used for all pages on the site, not just the page that was visited and any subpages it may have.

I hope this helps you out. Let me know if you run into any issues.

Posted at 11:38 AM on November 4th, 2009
  • Patrick

    Didn’t work for me. It works fine on Firefox, but on Explorer 8 and Opera browser, it didn’t fix the problem of the popup always coming up.

  • http://willfjohnston.com Will Johnston

    Hmm, that’s odd. I’ve used the code on a couple of sites and it worked with no problem.

    Did you put all of the code on one line or is it split between two lines? Not sure if that would make a difference, but you might try putting it all on one line.

    Try visiting this page and then visiting the home page.

    If you can’t get it to work, leave me a link to your site, I’d be happy to take a look at it.

  • http://www.mailchimp.com/ Jesse

    Will – just wanted to drop by and leave a note to say thanks for pointing out our oversight with this. As of our release a few weeks ago we started adding the cookie path to the generated code to alleviate this issue for users going forward.

More in Tech
Google Goes Down

UPDATE: And just that fast, it seems to be back up again. Early reports on Twitter indicate that it only...

Close