Skip to content

Instantly share code, notes, and snippets.

@EmilEriksen
Last active January 29, 2019 08:22
Show Gist options
  • Save EmilEriksen/b7d492229aa658439ce3 to your computer and use it in GitHub Desktop.
Save EmilEriksen/b7d492229aa658439ce3 to your computer and use it in GitHub Desktop.
Add event tracking to Ninja Forms submit
add_action( 'ninja_forms_display_js', 'prefix_track_form_submission' );
function prefix_track_form_submission() {
?>
<script>
//<![CDATA[
$( '.ninja-forms-form' ).on( 'submitResponse', function( e, response ) {
var errors = response.errors;
if ( errors == false ) {
// This is where you put the tracking code. This only fires if form submission is successfull
_gaq.push(['_trackEvent', 'Contact Form-Send', 'Click']);
}
});
//]]>
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment