Skip to content

Instantly share code, notes, and snippets.

@lesterchan
Created October 16, 2013 00:38
Show Gist options
  • Save lesterchan/7000884 to your computer and use it in GitHub Desktop.
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
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