Last active
November 18, 2021 21:54
-
-
Save schfkt/73602f2e2e95d346f4d2 to your computer and use it in GitHub Desktop.
Track JavaScript errors using Universal Analytics from Google.
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
function trackJavaScriptError(e) { | |
var ie = window.event || {}; | |
var message = e.message || ie.errorMessage || '<no message>' | |
var filename = e.filename || ie.errorUrl || '<no filename>'; | |
var lineno = e.lineno || ie.errorLine || '<no lineno>'; | |
var colno = e.colno || ie.errorColumn || '<no colno>'; | |
var source = filename + ':' + lineno + ':' + colno; | |
ga('send', 'event', 'JavaScript Exception', message, source, {'nonInteraction': 1}); | |
} | |
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