Created
April 11, 2014 19:13
-
-
Save steveosoule/10493422 to your computer and use it in GitHub Desktop.
Track JavaScript Errors with Google Analytics
This file contains 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
// FROM: http://davidwalsh.name/track-errors-google-analytics | |
// 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