Skip to content

Instantly share code, notes, and snippets.

@roborourke
Last active October 24, 2020 23:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roborourke/caac9ac383e1e01c94f0c8f332bd1adc to your computer and use it in GitHub Desktop.
Save roborourke/caac9ac383e1e01c94f0c8f332bd1adc to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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

@ivanli
Copy link

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