Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cristoferdomingues/0af6830885fad61b6a672c66cbaa54b1 to your computer and use it in GitHub Desktop.
Save cristoferdomingues/0af6830885fad61b6a672c66cbaa54b1 to your computer and use it in GitHub Desktop.
Track JavaScript errors using Universal Analytics from Google.
/**
* Track JS error details in Universal Analytics
*/
function trackJavaScriptError(e) {
var ie = window.event || {},
errMsg = e.message || ie.errorMessage;
var errSrc = (e.filename || ie.errorUrl) + ': ' + (e.lineno || ie.errorLine);
ga('send', 'exception', {
'exDescription': errSrc + ': ' + errMsg,
'exFatal': false
});
}
window.addEventListener('error', trackJavaScriptError, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment