Skip to content

Instantly share code, notes, and snippets.

@nitishn
Last active August 29, 2015 14:01
Show Gist options
  • Save nitishn/3897a955a645a36d0173 to your computer and use it in GitHub Desktop.
Save nitishn/3897a955a645a36d0173 to your computer and use it in GitHub Desktop.
Firing an analytics event on a link or form which changes the page sometimes causes the analytics event to be canceled. The proper way to handle this is to use a callback function like below.
var that = this;
event.preventDefault();
var callback = function() {
$(that).parents('#nl_form').submit();
}
_gaq.push(['_set','hitCallback', callback]);
_gaq.push(['_trackEvent', 'Newsletter Subscription', 'Started', window.location.pathname]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment