Skip to content

Instantly share code, notes, and snippets.

@edpichler
Last active December 20, 2015 03:59
Google analytics. Tracking a button event before submit the form when using JSF.
$("#frmButtons\\:btnExportWord").click(function (e) {
//track the event
_gaq.push(['_trackEvent', 'Decode', 'Decode copying', 'Export to Word']);
var button = $(this);
//create a delay and call the same click
if (button.data('tracked') != 'true') {
e.preventDefault(); //consume event if not tracked yet
setTimeout( function(){
button.data('tracked', 'true');
button.click(); //call again the submit
}, 300);//enough time to track the event
} else {
//reset the flag
button.data('tracked', 'false');
//let form being submited once the event is already tracked
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment