Exceptions - Web Tracking (analytics.js)

This guide describes how to send exceptions using analytics.js.


Exception measurement allows you to measure the number and type of crashes and exceptions that occur on your property.

There are 2 fields that can be sent with each exception hit:

Value Type Required Description
Description String No A description of the exception.
Is Fatal? Boolean No Indicates whether the exception was fatal. true indicates fatal.


To send an exception, you pass the ga function the send command with the exception hit type.

ga('send', 'exception');

You can pass a configuration object to specify values for optional fields. For example:

ga('send', 'exception', {
  'exDescription': 'DatabaseError',
  'exFatal': false

You may also want to pass additional app details such as name, and version if these values have not already been previously set. For example:

ga('send', 'exception', {
  'exDescription': 'DatabaseError',
  'exFatal': false,
  'appName': 'myApp',
  'appVersion': '1.0'

See the Exceptions Field Reference for details on fields related to exception tracking.


You typically send exceptions for which you've defined exception handling code. In the example below, an exception is sent when a configuration value has been requested but does not exist:

// The following is an example function that illustrates how to send an
// exception to Google Analytics.
 * Returns the requested configuration setting from the global config.
 * @param {string} settingsGroup Group from which to retrieve the setting.
 * @param {string} settingName The configuration setting to retrieve.
 * @return {string|undefined} The configuration setting or undefined if it
 *  does not exist.
function getConfigSetting(settingsGroup, settingName) {
  try {
    return configSettings[settingsGroup][settingName]
  } catch (err) {
    // Send the exception to Google Analytics.
    ga('send', 'exception', {
      'exDescription': err.message,
      'exFatal': true,
      'appName': APP_NAME,
      'appVersion': APP_VERSION