Skip to content

Instantly share code, notes, and snippets.

@roborourke

roborourke/nf-gtm.js

Last active Mar 23, 2020
Embed
What would you like to do?
Ninja Forms Google Tag Manager Trigger
<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>
@lonegoat

This comment has been minimized.

Copy link

@lonegoat lonegoat commented Feb 6, 2018

I found this works best if you're using a DOM Ready trigger in GTM, rather than a Page View one, as GTM may load before jQuery and it simply won't fire the event.

@nakitadog

This comment has been minimized.

Copy link

@nakitadog nakitadog commented Mar 5, 2018

Correct me if I am wrong but doesn't this fire for each form element?

@ivanli

This comment has been minimized.

Copy link

@ivanli ivanli commented Jul 27, 2018

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
You can’t perform that action at this time.