Skip to content

Instantly share code, notes, and snippets.

@klhall1987
Last active April 15, 2020 18:17
Show Gist options
  • Save klhall1987/2c8f4a363636bf71a593c580d49eda83 to your computer and use it in GitHub Desktop.
Save klhall1987/2c8f4a363636bf71a593c580d49eda83 to your computer and use it in GitHub Desktop.
Example of how to use the .on formSubmit listener.
<script>
jQuery( document ).ready( function() {
//Setup our on formSumbit Listener.
jQuery( document ).on( 'nfFormSubmitResponse', function() {
//Do Stuff
ga('send', 'event', 'Email List', 'Subscribed', 'New Subscriber');
});
});
</script>
@devinsays
Copy link

devinsays commented Feb 5, 2018

Perhaps the suggested code snippet in https://ninjaforms.com/event-tracking-for-ninja-forms-no-plugin/ should be something like this instead?

jQuery(document).on( 'nfFormReady', function() {
	nfRadio.channel('forms').on('submit:response', function(form) {
		ga( 'send', 'event', 'form', 'submit', form.data.settings.title, form.data.actions.save.sub_id );
	});
});

Advantages:

  • The example is a lot clearer for people that might want to additional filtering or send specific form data
  • Better defaults if used for all forms (it sends the form title and response id)

Haven't tested extensively, so not sure "form.data.actions.save.sub_id" is available if data is not stored (I'd assume not)? May need a few more tweaks to be truly drop-in.

@pbov
Copy link

pbov commented Jan 29, 2019

Didn't work out of the box - but nice approach though...

@sohaibgondal
Copy link

use simple if condition, to use form title as event label.

<script>
jQuery(document).ready(function(){
jQuery(document).on('nfFormSubmitResponse', function(event, response, id){
if(response.id == '2'){
ga('create', 'UA-**********-*', {'name': 'gaCode'}); // optional in case if you need to specify the tracker.
ga('gaCode.send', 'event', 'NF submissions', 'Form Submitted', 'Enquire');
}
});
});

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