Last active
April 15, 2020 18:17
-
-
Save klhall1987/2c8f4a363636bf71a593c580d49eda83 to your computer and use it in GitHub Desktop.
Example of how to use the .on formSubmit listener.
This file contains 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 ).ready( function() { | |
//Setup our on formSumbit Listener. | |
jQuery( document ).on( 'nfFormSubmitResponse', function() { | |
//Do Stuff | |
ga('send', 'event', 'Email List', 'Subscribed', 'New Subscriber'); | |
}); | |
}); | |
</script> |
Didn't work out of the box - but nice approach though...
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
Perhaps the suggested code snippet in https://ninjaforms.com/event-tracking-for-ninja-forms-no-plugin/ should be something like this instead?
Advantages:
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.