Skip to content

Instantly share code, notes, and snippets.

@varmais
Created April 10, 2014 19:07
Show Gist options
  • Save varmais/10412835 to your computer and use it in GitHub Desktop.
Save varmais/10412835 to your computer and use it in GitHub Desktop.
Track Javascript errors with Google Analytics
window.addEventListener('error', function(event) {
_gaq.push([
'_trackEvent',
'JS Error',
event.message,
event.filename + ': ' + event.lineno,
true
]);
});
// ajax errors with jquery
$(document).ajaxError(function(event, request, settings, error) {
_gaq.push([
'_trackEvent',
'Ajax error',
settings.url,
event.result,
true
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment