Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Created April 15, 2014 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbojinov/10775340 to your computer and use it in GitHub Desktop.
Save pbojinov/10775340 to your computer and use it in GitHub Desktop.
Track JavaScript Errors with Google Analytics
//http://davidwalsh.name/track-errors-google-analytics?utm_source=javascriptweekly&utm_medium=email
// Track basic JavaScript errors
window.addEventListener('error', function(e) {
_gaq.push([
'_trackEvent',
'JavaScript Error',
e.message,
e.filename + ': ' + e.lineno,
true
]);
});
// Track AJAX errors (jQuery API)
$(document).ajaxError(function(e, request, settings) {
_gaq.push([
'_trackEvent',
'Ajax error',
settings.url,
e.result,
true
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment