Skip to content

Instantly share code, notes, and snippets.

@tammalee
Last active September 10, 2018 19:26
Show Gist options
  • Save tammalee/03d7feb2317affbcffc97ff196512f9d to your computer and use it in GitHub Desktop.
Save tammalee/03d7feb2317affbcffc97ff196512f9d to your computer and use it in GitHub Desktop.
MailChimp 4 WordPress GTM data layer push after form submission
/**
* Hooking into MailChimp for WordPress
* MC4WP JS Form Events: https://mc4wp.com/kb/javascript-form-events/
* Form success
*/
(function($) {
$(document).ready(function() {
mc4wp.forms.on('748.success', function(form) {
//GTM Data Layer Code Goes Here
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event' : 'formSubmissionSuccess',
'formId' : 'newsletterForm'
});
});
});
})(jQuery);
@erikmolenaarnl
Copy link

erikmolenaarnl commented May 7, 2018

Hi,

I assume this code can be added to "Form code" within the MC4WP form code at tab "Fields". E.g.: https://www.screencast.com/t/vCbeehc8.
Is there any reason in particular why you wrapped it in a jQuery document.ready?

Or did you intend to apply it as a custom HTML tag in GTM?

Looking forward to your reply. Thanks!

@tammalee
Copy link
Author

tammalee commented Sep 10, 2018

Ah hello! I hadn't realized I had a comment. This is far too late to be of use to you, I'm sure, but I usually put that code in its own js file. As far as I know, this code still works with the MailChimp 4 WordPress plugin.

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