5

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

Piyush
  • 158
  • 2
  • 14

3 Answers3

7

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
silvaric
  • 1,668
  • 17
  • 27
  • how did you handle exception? means i dont want to write try-catch in each and every function. – Paras Gandhi May 09 '14 at 11:41
  • 2
    I'm using this : http://www.cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html - download the example "UncaughtExceptions.zip" and in the "handleException:(NSException *)exception" you can call what you want – silvaric May 09 '14 at 12:38
1

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!

Community
  • 1
  • 1
Amar
  • 13,202
  • 7
  • 53
  • 71
  • Thanks for your answer. But, how can I implement this(symbolicating crash report) with Google analytics? I have to track the crashes of the app that is on App store. – Piyush Aug 29 '13 at 06:53
  • @Piyush You just need to add the above line of code in your applications `application:didFinishLaunchingWithOptions:` function. If your app is already on app store you might want to add this feature and update it. – Amar Aug 29 '13 at 06:55
  • @Piyush Also while updating the IPA on app store, keep the `.dSYM` file since it will be required for symbolicating the crash reports that you receive. – Amar Aug 29 '13 at 06:56
  • I have written the above line in application:didFinishLaunchingWithOptions function. But, I want to track the line(or function) at which, the app crashes. I am getting this message in "Crashes & Exceptions" tab:- `NSInvalidArgumentException Trace: -[NSObject(NSObject) doesNotRecognizeSelector:] ___forwarding___ _CF_forwarding_prep_0 CFStringGetLength _CPCreateUT`. Now, I want to know where this crash is happening and by which reason? – Piyush Aug 29 '13 at 07:00
  • @Piyush You need to check the description field on the GA dashboard which will have the stack trace. That will show you which is the function in your application which lead to the crash. – Amar Aug 29 '13 at 07:03
  • I just mentioned the description message of GA dashboard. But, I am not getting any idea the reason of crash. – Piyush Aug 29 '13 at 07:07
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/36439/discussion-between-piyush-and-amar) – Piyush Aug 29 '13 at 07:10
  • @Piyush Hmmm that looks like a very little information to pin point the location crash. Not sure how you can move ahead with that. – Amar Aug 29 '13 at 07:10
  • @Piyush have you figured out how to get the complete stack trace from google analytics ?? – user3124624 Dec 10 '15 at 09:57
  • @Amar have you figured out how to get the complete stack trace from google analytics ?? – user3124624 Dec 10 '15 at 09:57
0

Swift 3

    GAI.sharedInstance().trackUncaughtExceptions = true
Aayushi
  • 787
  • 10
  • 14