Skip to content

Instantly share code, notes, and snippets.

@anilex
Created April 12, 2014 10:08
Show Gist options
  • Save anilex/10528188 to your computer and use it in GitHub Desktop.
Save anilex/10528188 to your computer and use it in GitHub Desktop.
/**
* Track JS error details in Universal Analytics
*/
function trackJavaScriptError(e) {
var errMsg = e.message;
var errSrc = e.filename + ': ' + e.lineno;
ga('send', 'event', 'JavaScript Error', errMsg, errSrc, { 'nonInteraction': 1 });
}
/**
* Cross-browser event listener
*/
if (window.addEventListener) {
window.addEventListener('error', trackJavaScriptError, false);
} else if (window.attachEvent) {
window.attachEvent('onerror', trackJavaScriptError);
} else {
window.onerror = trackJavaScriptError;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment