Take our developer survey. We want your feedback so we can learn how to improve Google Analytics, and make it an even better tool for you.

Crashes & Exceptions - iOS SDK

This document provides a high-level overview of crash and exception measurement using the Google Analytics SDK for iOS v3.

Overview

Crash and exception measurement allows you to measure the number and type of crashes and exceptions that occur in your app. An exception has these fields:

Field Name Tracker Field Type Required Description
Description kGAIExDescription NSString No A description of the exception (up to 100 characters). Accepts nil.
isFatal kGAIExFatal BOOL Yes Indicates whether the exception was fatal. YES indicates fatal.

Crash and exception data is available primarily in the Crash and Exceptions report.

Caught Exceptions

Caught exceptions are errors in your app for which you've defined exception handling code, such as the occasional timeout of a network connection during a request for data.

Measure a caught exception by setting the exception field values on the tracker and sending the hit, as in this example:

/*
 * An app tries to load a list of high scores from the cloud. If the request
 * times out, an exception is sent to Google Analytics
 */
@try {

  // Request some scores from the network.
  NSArray *highScores = [self getHighScoresFromCloud];

}
@catch (NSException *exception) {

    // May return nil if a tracker has not already been initialized with a
    // property ID.
    id tracker = [[GAI sharedInstance] defaultTracker];

    [tracker send:[[GAIDictionaryBuilder
        createExceptionWithDescription:@"Connection timeout"  // Exception description. May be truncated to 100 chars.
                             withFatal:@NO] build]];  // isFatal (required). NO indicates non-fatal exception.
}

Uncaught Exception Measurement

Uncaught exceptions represent instances where your app encountered unexpected conditions at runtime and are often fatal, causing the app to crash. Uncaught exceptions can be sent to Google Analytics automatically by setting the trackUncaughtExceptions property to YES. For example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [[GAI sharedInstance] setTrackUncaughtExceptions:YES];
  return YES;
}

When using automatic exception measurement, keep the following in mind:

  • All exceptions sent using automatic exception measurement are reported as fatal in Google Analytics.
  • By default, the description field is automatically set using the exception type, class name, method name and thread name.