Last active
September 10, 2018 19:26
-
-
Save tammalee/03d7feb2317affbcffc97ff196512f9d to your computer and use it in GitHub Desktop.
MailChimp 4 WordPress GTM data layer push after form submission
This file contains hidden or 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
/** | |
* 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); |
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
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!