Analytics exception tracking analytics.js exception tracking report

Google Universal Analytics has an exception type for deletions

ga('send', 'exception', { 'exDescription': 'DatabaseError' }); 

I expected that I could just go into the Google Analytics console and find the exception report at the same level as the "events", but it is nowhere to be seen.

The Android and iOS APIs say Crash and exception data is available primarily in the Crash and Exceptions report , but I cannot find a report with this name.

+55
exception-handling google-analytics
Feb 12 '14 at 4:11
source share
5 answers

Figured it out. I'm not sure why they do not do this as an inline report, but maybe someday.

I made my own widget in the control panel with an Exception Description for measurement and Failures for the metric:

enter image description here

Which gives me a report like this:

enter image description here

You can also go to the Customization tab and create your own report to give you an error table, and then add it to your dashboard.

enter image description here

Used with this global exception handler

 if (typeof window.onerror == "object") { window.onerror = function (err, url, line) { if (ga) { ga('send', 'exception', { 'exDescription': line + " " + err }); } }; } 

You can place this handler anywhere in your Javascript initialization - it depends on how you configured all your JS files. Alternatively, you can simply put it in the <script> tag next to the html tag tag.

+90
Feb 12 '14 at 4:21
source share

I took the Simon_Weaver guide to create a custom report a few steps further and developed a fairly comprehensive report on exceptions from Google Analytics. I figured it might be worth sharing, so I uploaded it to the GA solution gallery.

My Template: Exclusion Report for Google Analytics

+24
Feb 25 '15 at 18:31
source share

I just wanted to expand the excellent answer on @Simon_Weaver a bit to provide error reports with a few additional details:

  • Make sure ga() defined before trying to call it (since the error can be triggered before loading the Google Analytics library).
  • Exception log line numbers and column index in Analytics reports (although the minimal JavaScript code used in production can be difficult to read).
  • Issue any previously defined window.onerror callback.
 /** * Send JavaScript error information to Google Analytics. * * @param {Window} window A reference to the "window". * @return {void} * @author Philippe Sawicki <https://github.com/philsawicki> */ (function (window) { // Retain a reference to the previous global error handler, in case it has been set: var originalWindowErrorCallback = window.onerror; /** * Log any script error to Google Analytics. * * Third-party scripts without CORS will only provide "Script Error." as an error message. * * @param {String} errorMessage Error message. * @param {String} url URL where error was raised. * @param {Number} lineNumber Line number where error was raised. * @param {Number|undefined} columnNumber Column number for the line where the error occurred. * @param {Object|undefined} errorObject Error Object. * @return {Boolean} When the function returns true, this prevents the * firing of the default event handler. */ window.onerror = function customErrorHandler (errorMessage, url, lineNumber, columnNumber, errorObject) { // Send error details to Google Analytics, if the library is already available: if (typeof ga === 'function') { // In case the "errorObject" is available, use its data, else fallback // on the default "errorMessage" provided: var exceptionDescription = errorMessage; if (typeof errorObject !== 'undefined' && typeof errorObject.message !== 'undefined') { exceptionDescription = errorObject.message; } // Format the message to log to Analytics (might also use "errorObject.stack" if defined): exceptionDescription += ' @ ' + url + ':' + lineNumber + ':' + columnNumber; ga('send', 'exception', { 'exDescription': exceptionDescription, 'exFatal': false, // Some Error types might be considered as fatal. 'appName': 'Application_Name', 'appVersion': '1.0' }); } // If the previous "window.onerror" callback can be called, pass it the data: if (typeof originalWindowErrorCallback === 'function') { return originalWindowErrorCallback(errorMessage, url, lineNumber, columnNumber, errorObject); } // Otherwise, Let the default handler run: return false; }; })(window); // Generate an error, for demonstration purposes: //throw new Error('Crash!'); 



Edit: As @Simon_Weaver already noted, Google Analytics now has exception tracking documentation (which I had to refer to in my original answer - sorry, rookie mistake!):

+6
Apr 10 '15 at 2:24
source share

This is what I came up with, so you don't need to include code everywhere. Just add new ErrorHandler(); to every .js file. This was done for the Chrome extension, but I have to work anywhere. I implement the actual ga () stuff in a separate file (hence app.GA), but you can also bake it here.

 /* * Copyright (c) 2015-2017, Michael A. Updike All rights reserved. * Licensed under the BSD-3-Clause * https://opensource.org/licenses/BSD-3-Clause * https://github.com/opus1269/photo-screen-saver/blob/master/LICENSE.md */ // noinspection ThisExpressionReferencesGlobalObjectJS (function(window, factory) { window.ExceptionHandler = factory(window); }(this, function(window) { 'use strict'; return ExceptionHandler; /** * Log Exceptions with analytics. Include: new ExceptionHandler();<br /> * at top of every js file * @constructor * @alias ExceptionHandler */ function ExceptionHandler() { if (typeof window.onerror === 'object') { // global error handler window.onerror = function(message, url, line, col, errObject) { if (app && app.GA) { let msg = message; let stack = null; if (errObject && errObject.message && errObject.stack) { msg = errObject.message; stack = errObject.stack; } app.GA.exception(msg, stack); } }; } } })); 
+1
May 18 '17 at 21:15
source share

Simon_Weaver,

I added

 if (typeof window.onerror == "object") { window.onerror = function (err, url, line) { if (ga) { ga('send', 'exception', { 'exDescription': line + " " + err }); } }; } 

and my page also generates an error, but I cannot see it in the exception report. Is this exception report generated after being added to analytics?

0
Apr 20 '16 at 7:20
source share



All Articles