Last active
December 27, 2015 02:39
-
-
Save fiftyandfifty/7253946 to your computer and use it in GitHub Desktop.
Using the donately.success event: Pushing donor information to a mailchimp mailing list after Donately donation success
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
jQuery( window ).load(function() { | |
function receiveMessage(event){ | |
try {var data = JSON.parse(event.data);} | |
catch (e) {var data = event.data;} | |
if(data.event == 'donately.success'){ | |
var chimpurl = 'https://us1.api.mailchimp.com/2.0/lists/subscribe.json'; | |
var chimpvars = { | |
"apikey" : '1234567890', | |
"id" : '123', | |
"email" : {"email": data.data.donation_form.email}, | |
"merge_vars" : { | |
"fname" : data.data.donation_form.first_name, | |
"lname" : data.data.donation_form.last_name | |
} | |
}; | |
make_ajax_request(chimpurl, chimpvars); | |
} | |
} | |
function make_ajax_request(url, vars) { | |
console.log('make_ajax_request', url, vars); | |
} | |
if (window.addEventListener){ | |
window.addEventListener('message', receiveMessage, false); | |
} | |
else if (window.attachEvent){ | |
window.attachEvent('message', receiveMessage); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<script class="donately-formjs" | |
src="http://demo.dntly.local:3000/assets/js/v1/form.js" | |
type="text/javascript" | |
async="async" | |
data-donately-id="198"> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment