Created
August 5, 2015 18:06
-
-
Save james2doyle/ce85dee7668cb33f413c to your computer and use it in GitHub Desktop.
jQuery contact form submit with Google Analytics event
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
$('#contact-form').submit(function(e) { | |
// delay the submit | |
e.preventDefault(); | |
// we need this to call the form in a scoped function | |
var self = this; | |
ga('send', { | |
eventAction: "submit", | |
eventCategory: "form", | |
eventLabel: "contact-form", | |
hitType: "event", | |
useBeacon: true, // useBeacon API, allows sending after page change | |
hitCallback: function() { | |
// now that the form has finished, submit normally | |
self.submit(); | |
} | |
}); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment