Last active
August 29, 2015 14:03
-
-
Save jerkovicl/40075dd28af05fc269d8 to your computer and use it in GitHub Desktop.
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
/** | |
* 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 }); | |
} | |
//for compatibility( IE9 and blow), the code should be this: | |
function trackJavaScriptError(e) { | |
var ie = window.event, | |
errMsg = e.message || ie.errorMessage; | |
var errSrc = (e.filename || ie.errorUrl) + ': ' + (e.lineno || ie.errorLine); | |
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