Last active
August 29, 2015 14:16
-
-
Save kimmobrunfeldt/26a76e1252bf57f17067 to your computer and use it in GitHub Desktop.
Google Analytics error reporting skeleton. NOTE THAT THIS DOES NOT WORK!!! This is just an example how to hook to window.onerror
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
| function sendErrorToAnalytics(err) { | |
| console.log('Sending error to analytics', err); | |
| // WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| // Google analytics exception's exDescription max length is 150 bytes. | |
| // USE ANOTHER EXCEPTION LOGGING SERVICE IF YOU NEED TO LOG E.G. STACKTRACES | |
| ga('send', 'exception', { | |
| exDescription: err.stack, | |
| fatal: false | |
| }); | |
| } | |
| var Promise = require('bluebird'); | |
| Promise.onPossiblyUnhandledRejection(function(error) { | |
| throw error; | |
| }); | |
| // The first 3 parameters are quite standard but some browsers offer the actual | |
| // error object as fifth parameter. | |
| window.onerror = function onGlobalError(message, file, line, column, errorObj) { | |
| var shortDescription = file + '(' + line + '): ' + message; | |
| if (errorObj) { | |
| sendErrorToAnalytics({ | |
| stack: shortDescription + '\n' + errObj.stack; | |
| }); | |
| } else { | |
| sendErrorToAnalytics({ | |
| stack: shortDescription | |
| }); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment