feat(aio): report application errors to Google Analytics (#22011)
This is a basic implementation of error logging using the limited facilities provided by Google Analytics. Errors within the Angular app itself will be handled by a new `ReportingErrorHandler` service, which overrides and extends the built-in `ErrorHandler`. Further, errors outside the app, which arrive at `window.onerror` will also be reported to Google Analytics. Closes #21943 PR Close #22011
This commit is contained in:

committed by
Miško Hevery

parent
e442881ead
commit
98001a065d
@ -52,6 +52,38 @@
|
||||
</script>
|
||||
<!-- End Google Analytics -->
|
||||
|
||||
<script>
|
||||
// Report fatal errors to Google Analytics
|
||||
window.onerror = function() {
|
||||
ga('send', 'exception', {exDescription: formatError.apply(null, arguments), exFatal: true});
|
||||
|
||||
function formatError(msg, url, line, col, e) {
|
||||
var stack;
|
||||
msg = msg.replace(/^Error: /, '');
|
||||
if (e) {
|
||||
stack = e.stack
|
||||
// strip the leading "Error: " from the stack trace
|
||||
.replace(/^Error: /, '')
|
||||
// strip the message from the stack trace, if present
|
||||
.replace(msg + '\n', '')
|
||||
// strip leading spaces
|
||||
.replace(/^ +/gm, '')
|
||||
// strip all leading "at " for each frame
|
||||
.replace(/^at /gm, '')
|
||||
// replace long urls with just the last segment: `filename:line:column`
|
||||
.replace(/(?: \(|@)http.+\/([^/)]+)\)?(?:\n|$)/gm, '@$1\n')
|
||||
// replace "eval code" in Edge
|
||||
.replace(/ *\(eval code(:\d+:\d+)\)(?:\n|$)/gm, '@???$1\n')
|
||||
} else {
|
||||
line = line || '?';
|
||||
col = col || '?';
|
||||
stack = url + ':' + line + ':' + col;
|
||||
}
|
||||
return (msg + '\n' + stack).substr(0, 150);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<script>
|
||||
if (window.document.documentMode) {
|
||||
// polyfill IE11 in a blocking way
|
||||
|
Reference in New Issue
Block a user