Created
August 15, 2013 21:53
-
-
Save chrisjimallen/6245322 to your computer and use it in GitHub Desktop.
How to make sure the event is tracked BEFORE the form is submitted.
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
jQuery(document).ready(function($){ | |
$('form').submit(function(event){ | |
//if analytics object exists | |
if(window._gat){ | |
event.preventDefault(); | |
optinForm = this; | |
_gaq.push(['_set','hitCallback', function(){ | |
optinForm.submit(); | |
}]); | |
_gaq.push(['_trackEvent', 'Forms', 'Submit', 'hbsanewtraffic']); | |
} | |
//if no analytics object, service as normal | |
}); | |
}); |
thanks nasieti, this will be useful
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great work on this issue. and this way you can hook it up directly in the form's onSubmit too (if you can't rely on jquery or want/need to keep the code in the form itself)