Skip to content

Instantly share code, notes, and snippets.

@crates
Created February 11, 2020 17:46
Show Gist options
  • Save crates/9c2af3019eb75b87214370bc11ae7491 to your computer and use it in GitHub Desktop.
Save crates/9c2af3019eb75b87214370bc11ae7491 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 errMsg = e.message;
var errSrc = e.filename + ': ' + e.lineno;
ga('send', 'event', 'JavaScript Error', errMsg, errSrc, { 'nonInteraction': 1 });
}
window.addEventListener('error', trackJavaScriptError, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment