Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track crash using Google Analytics iOS

Hello
I am using Google Analytics in one of my iPhone app. I am tracking the app installations, screen visits and click events.
Now, I want to track the crashes & exceptions in the app with reason and its location(by location, I mean method name, line number or anything else). I have read the the document provided by google, but didn't get anything useful.
Can anyone help me with this? Any example would be really appreciated.


Update:- Here, I am attaching the screenshot link of GA dashboard.

enter image description here

like image 732
Piyush Avatar asked Aug 29 '13 06:08

Piyush


2 Answers

You can send the backtrace (already symbolicated). I set sendUncaughtExceptions = FALSE and manually send.

id tracker = [[GAI sharedInstance] defaultTracker];

NSString * model = [[UIDevice currentDevice] model];
NSString * version = [[UIDevice currentDevice] systemVersion];
NSArray * backtrace = [exception callStackSymbols];
NSString * description = [NSString stringWithFormat:@"%@.%@.%@.Backtrace:%@",
                          model,
                          version,
                          exception.description,
                          backtrace];

[tracker send:[[GAIDictionaryBuilder
                createExceptionWithDescription:description  // Exception description. May be truncated to 100 chars.
                withFatal:NO] build]];     

(model and version is optional)

The backtrace will have < redacted > but the most important class and method will be symbolicate (where the crash occurred) and you will know where is

** EDIT **

How handle exception

  1. Detail explanation
  2. Download the example "UncaughtExceptions.zip"
  3. On the UncaughtExceptionHandler.m, inside of the method "handleException:(NSException *)exception" you can do what you want, in my case i have other method to validate the exception and after that send to GAI
like image 80
silvaric Avatar answered Nov 10 '22 14:11

silvaric


I have not used the Google Analytics crash reporting feature yet, but found this which could be helpful.

You can have Google Analytics(v2) report uncaught exceptions i.e. crashes by using this code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GAI sharedInstance].sendUncaughtExceptions = YES; // Enable 

  // ... the rest of your code, include other GAI properties you want to set.
}

I don't think these will be symbolicated crash reports as the device is unable to symbolicate it. So you may have to symbolicate the received crash reports by yourself to understand the line number in code which caused this crash.

Check out Where can I view the Google Analytics iOS crash logs?

Refer: Symbolicating iPhone App Crash Reports

Hope that helps!

like image 24
Amar Avatar answered Nov 10 '22 16:11

Amar