Created
October 16, 2013 00:38
-
-
Save lesterchan/7000884 to your computer and use it in GitHub Desktop.
Use Google Analytics (GA) events (https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide) to track & log JavaScript exceptions
This file contains hidden or 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
Utility.send_exception_to_ga = function() | |
{ | |
if(true || window.settings && window.settings.debug) | |
{ | |
return; | |
} | |
var gOldOnError = window.onerror; | |
window.onerror = function(message, url, line) { | |
var e_obj = [ | |
"_trackEvent" | |
, "JS Exception Error" | |
, message | |
, (url + " (" + line + ")") | |
, 0 | |
, true | |
]; | |
if (typeof(_gaq) === "object") { | |
_gaq.push(e_obj); | |
} | |
if (gOldOnError) | |
{ | |
return gOldOnError(message, url, line); | |
} else { | |
console.log("Unhandled Exception"); | |
console.log(e_obj); | |
} | |
return false; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment