You can specify a custom callback function in the tracker object.
_gaq.push(['_set', 'hitCallback', function(){}]);
The callback is called after "luck sent successfully."
If you want to track the click on the submit button and submit the form after that, you can use the following code (uses jQuery) for your event:
var _this = this; // The form input element that was just clicked _gaq.push(['_set','hitCallback',function() { $(_this).parents('form').first().submit(); // Submit underlying form }]); _gaq.push(['_trackEvent', 'My category', 'My action']); return !window._gat; // Ensure that the event is bubbled if GA is not loaded
Or like onclick one insert for your <input type="submit"> element:
onclick="var _this=this;_gaq.push(['_set','hitCallback',function(){$(_this).parents('form').first().submit();}]);_gaq.push(['_trackEvent','My category','My action']);return !window._gat;"
What he does to track the My category/My action event, uses jQuery to find the submit button's main form element, just clicked, and then submit the entire form.
See: Google Analytics - Submitting data to Google Analytics - Hit callback (thanks to superacuo)
UPDATE If you use modern analytics.js code with a specific ga () function, you can write the following:
var _this = this; ga('send', 'event', 'My category', 'My action', { 'hitCallback': function() { $(_this).parents('form').first().submit(); } }); return !window.ga;
flu Sep 17 '12 at 14:34 2012-09-17 14:34
source share