Skip to content

Instantly share code, notes, and snippets.

@jaan
Last active August 29, 2015 14:16
Show Gist options
  • Save jaan/60eebd308c7ebc61555b to your computer and use it in GitHub Desktop.
Save jaan/60eebd308c7ebc61555b to your computer and use it in GitHub Desktop.
How to track javascript/jquery errors in google anlaytics?
// Track javaScript errors
window.addEventListener('error', function (err) {
var lineAndColumnInfo = err.colno ? ' line:' + err.lineno +', column:'+ err.colno : ' line:' + e.lineno;
ga(
'send',
'event',
'JavaScript Error',
err.message,
err.filename + lineAndColumnInfo + ' -> ' + navigator.userAgent,
0,
true
);
});
// jQuery errors handler (jQuery API)
jQuery.error = function (message) {
_gaq.push([
'_trackEvent',
'jQuery Error',
message,
navigator.userAgent,
0,
true
]);
}
Source: http://blog.gospodarets.com/track_javascript_angularjs_and_jquery_errors_with_google_analytics/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment