Last active
October 24, 2020 23:16
-
-
Save roborourke/caac9ac383e1e01c94f0c8f332bd1adc to your computer and use it in GitHub Desktop.
Ninja Forms Google Tag Manager Trigger
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
<script> | |
jQuery( document ).on( 'nfFormReady', function() { | |
nfRadio.channel('forms').on('submit:response', function(form) { | |
window.dataLayer = window.dataLayer||[]; | |
dataLayer.push({ | |
event: 'ninjaFormSubmission', | |
eventData: form.data, | |
formID: form.data.form_id, | |
formTitle: form.data.settings.title | |
}) | |
}) | |
} ) | |
</script> |
With multiple forms on a single page, the current implementation would fire 2x data pushes. It's better to use
jQuery( document ).one( 'nfFormReady', function() {
...
}
Then the data push only happens once on any form submit on the page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Correct me if I am wrong but doesn't this fire for each form element?