Skip to content

Instantly share code, notes, and snippets.

@scottmagdalein
Last active March 15, 2023 18:01
Show Gist options
  • Star 70 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save scottmagdalein/259d878ad46ed6f2cdce to your computer and use it in GitHub Desktop.
Save scottmagdalein/259d878ad46ed6f2cdce to your computer and use it in GitHub Desktop.
Make the Mailchimp Subscriber popup appear on click
<!-- This is the HTML element that, when clicked, will cause the popup to appear. -->
<button id="open-popup">Subscribe to our mailing list</button>
<script type="text/javascript" src="//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>
<script>
function showMailingPopUp() {
require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us11.list-manage.com","uuid":"YOUR_UUID_GOES_HERE","lid":"YOUR_LID_GOES_HERE"}) })
document.cookie = "MCEvilPopupClosed=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
};
document.getElementById("open-popup").onclick = function() {showMailingPopUp()};
</script>
@ryanlabelle
Copy link

My original code is in this tread already.

https://gist.github.com/scottmagdalein/259d878ad46ed6f2cdce#gistcomment-2929907

Sorry, I can't check your code. I wish had more time to help out.

@Naren-hybreeder
Copy link

I tried the same code but it's not working. I don't know where is the issue. I tried to display the alert on the click, It is displaying but popup not displaying.

@ryanlabelle
Copy link

Sorry, I wish I could help. Perhaps someone in this thread has a solution?

@heitoralthmann
Copy link

heitoralthmann commented Feb 12, 2020

I can confirm this is working for me as of the date of this comment:

<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>
<script type="text/javascript">
  window.openMailchimpPopup = function() {
    window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"YOUR_SERVER_BASE_URL","uuid":"YOUR_UUID","lid":"YOUR_LIST_ID","uniqueMethods":true}) })
    document.cookie = 'MCPopupClosed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
    document.cookie = 'MCPopupSubscribed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
  }
</script>
<a class="mailchimp-subscription-block__button" onclick="openMailchimpPopup()">SUBSCRIBE</a>

I found the secret behind this to be searching for mailchimp cookies (usually MC something) on the Developer Console and setting them appropriately.

@dseeker
Copy link

dseeker commented Feb 13, 2020

@heitoralthmann solution works here

@ilium007
Copy link

Copy and pasted code from @heitoralthmann but still can't get the JS file

Loading failed for the <script> with source “file:///js/signup-forms/popup/unique-methods/embed.js”.

@heitoralthmann
Copy link

heitoralthmann commented Mar 26, 2020

@ilium007 I believe you should be loading embed.js from the cloud at //downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js and not from your local machine/server (file:///js/signup-forms/popup/unique-methods/embed.js).

Double check the src attribute for the <script> where you're loading Mailchimp's embed.js.

@kibblewhite
Copy link

kibblewhite commented Apr 2, 2020

Could I also add to the list of code suggestions? I've been trying with a bit of code that works both on WordPress and stand alone pages and I seem to have successfully integrated it with a timer of sorts. So a user visits the page, it waits for a fixed duration of time (3s in this case) displays the form and then if the user cancels but then decides that they do want to subscribe, I have added a button for them to get that form back. If they click the 'subscribe-toggle' button so the form appears, but then refreshes/revisit the page the form should re-appear automatically again after 3 seconds. Notes: Script requires jQuery, won't work from local computer file system, needs to be hosted on a web service.

<a id="subscribe-toggle" class="button">Subscribe</a>

<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>
<script type="text/javascript">
	(function( $ ) {
		function openMailchimpPopup() {
			window.dojoRequire( ["mojo/signup-forms/Loader"], function(L) { L.start( { "baseUrl": "YOUR_SERVER_BASE_URL" , "uuid": "YOUR_UUID" , "lid": "YOUR_LIST_ID" , "uniqueMethods": true } ) } );
		}
		$(function() {
			$( window ).load(function() { setTimeout( openMailchimpPopup, 3000 ); } );
			$( 'a#subscribe-toggle', document ).on( 'click', function( e ) {
				$( '[id^=PopupSignupForm_]', document ).remove();
				document.cookie = 'MCPopupClosed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
				document.cookie = 'MCPopupSubscribed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
				openMailchimpPopup();
			} );
		} );
	} )( jQuery );
</script>

@kkozma-liquid
Copy link

@heitoralthmann Thank you for that! Mailchimp needs add an event listener soon!

@em1991
Copy link

em1991 commented Apr 6, 2020

@heitoralthmann
Where can you find the developer options on mailchimp?
I've had tried adding this code to my wordpress site, however it still appears once.

`<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>

<script type="text/javascript">window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us10.list-manage.com","uuid":"","lid":"","uniqueMethods":true}) }) document.cookie = 'MCPopupClosed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;'; document.cookie = 'MCPopupSubscribed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';}</script>`

@Lukexample
Copy link

Lukexample commented Apr 22, 2020

Hi there!
I need some help with this common MailChimp issue.
@heitoralthmann
I used the same code as you but now the popup doesn't even appear once.

Here the code I used:

<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>
<script type="text/javascript">
  window.openMailchimpPopup = function() {
    window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.u...","uuid":"92ce1...","lid":"6afc...","uniqueMethods":true}) })
    document.cookie = 'MCPopupClosed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
    document.cookie = 'MCPopupSubscribed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
  }
</script>

Does someone have the solution to this problem?
Thx!

@omar93102
Copy link

omar93102 commented May 14, 2020

This code really saved me! It does exactly what I wanted.
I got a problem, when I double click the function the pop up get fixed and I can't close it up. Does anyone knows how to solve this problem? I put the function inside an <a><img/></a> element.

@genunlimited
Copy link

I'm confused as to where you all are getting the popup form code in mail chimp? My mail chimp just asks if I want it turned on and to connect the site and does not deliver the code. Where would I find that?

@irugoy
Copy link

irugoy commented Jul 3, 2020

I'm confused as to where you all are getting the popup form code in mail chimp? My mail chimp just asks if I want it turned on and to connect the site and does not deliver the code. Where would I find that?

Hi there, as far as I've experienced recently in one of our projects, this "window.dojoRequire" option is not longer possible since 16 June 2020 and it just throws an error and conflicts with some other JS code :( .

Has anyone had same issue?

@graz68a
Copy link

graz68a commented Mar 15, 2023

Hi

I am using this test page in my site

<html>
<head>
<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>
<script type="text/javascript">
	(function( $ ) {
		function openMailchimpPopup() {
			window.dojoRequire( ["mojo/signup-forms/Loader"], function(L) { L.start( { "baseUrl":"gomoot.us17.list-manage.com","uuid":"my_uuid","lid":"my_id","uniqueMethods":true } ) } );
		}
		$(function() {
			$( window ).load(function() { setTimeout( openMailchimpPopup, 3000 ); } );
			$( 'a#subscribe-toggle', document ).on( 'click', function( e ) {
				$( '[id^=PopupSignupForm_]', document ).remove();
				document.cookie = 'MCPopupClosed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
				document.cookie = 'MCPopupSubscribed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
				openMailchimpPopup();
			} );
		} );
	} )( jQuery );
</script>
</head>
<body>
<button id="themo-get-notified">Subscribe to our mailing list</button>
</body>
</html>

but it does not work, of course I replaced uuid with my uuid and lid with my id .

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment