Created
April 29, 2015 17:54
-
-
Save atma/947aafb440ce735ecae5 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
// jQuery AJAX errors handler | |
$(document).ajaxError(function (event, request, settings) { | |
ga( | |
'send', | |
'event', | |
'jQuery Ajax Error', | |
settings.url, | |
JSON.stringify({ | |
result: event.result, | |
status: request.status, | |
statusText: request.statusText, | |
crossDomain: settings.crossDomain, | |
dataType: settings.dataType | |
}), | |
0, | |
true | |
); | |
}); |
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
// jQuery errors handler | |
jQuery.error = function (message) { | |
ga( | |
'send', | |
'event', | |
'jQuery Error', | |
message, | |
navigator.userAgent, | |
0, | |
true | |
); | |
} |
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
// Pure JavaScript errors handler | |
window.addEventListener('error', function (err) { | |
var lineAndColumnInfo = err.colno ? ' line:' + err.lineno +', column:'+ err.colno : ' line:' + err.lineno; | |
ga( | |
'send', | |
'event', | |
'JavaScript Error', | |
err.message, | |
err.filename + lineAndColumnInfo + ' -> ' + navigator.userAgent, | |
0, | |
true | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment