Last active
December 20, 2015 03:59
Google analytics. Tracking a button event before submit the form when using JSF.
This file contains hidden or 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
$("#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