I've been banging my head against a wall for hours on this one. The v4 docs for Google Analytics specify 2 different ways of getting your app to report uncaught exceptions. I can get neither to work. In both cases I see lines like this in LogCat when I trigger the uncaught exception to occur in my app (using dummy names for my own code):
08-17 17:33:30.248: V/GAV4(8968): Thread[main,5,main]: Tracking Exception: MyException (@MyClass:myMethod:143) {main}
08-17 17:33:30.248: V/GAV4(8968): Thread[main,5,main]: Dispatch call queued. Dispatch will run once initialization is complete.
08-17 17:33:30.248: V/GAV4(8968): Thread[main,5,main]: Passing exception to original handler.
...followed by the stacktrace for my exception and then finally:
08-17 17:33:44.282: I/Process(8968): Sending signal. PID: 8968 SIG: 9
From LogCat it looks like GA never actually dispatches the exception to Google's servers!
If someone has managed to get uncaught exceptions being reported in their Google Analytics Console it would be fantastic if they could share with us how they did it, please. I've seen other people on SO with queries like this (e.g., here and here) but no confirmation that uncaught exceptions are being reported.
I've got screen views showing up in the GA Console so I must be doing something right. But not uncaught exceptions. I'm assuming one should be looking for them under Behavior > Crashes and Exceptions, and I've set the end date to include today (it seems to be set to yesterday by default). Finally, in my analytics_global_config.xml I have:
<integer name="ga_dispatchPeriod">1</integer>
because otherwise the default is 1800 seconds, in which case I assume exceptions would not be seen in the GA console for at least 30 minutes after they occurred. ga_dryRun
is false too.
As @xitx kindly pointed out, it looks like there's a bug in later versions of the Google Play Services library installed on people's devices. Because when I ran my existing code on an emulator for a relatively old device (API 9, and presumably running an old Google Play Services library) the crash did get reported to GA's console automatically. Here's what LogCat said when the crash occurred:
And this is what the GA Console showed within a minute or so of the crash:
I know you only get the first line of the stacktrace but that will do for me for now. Various other people have their own approaches for getting the whole stacktrace (see @xitx's comments above and here for example).
So I plan to use my existing code and wait for Google to ship the fix to their bug in a later version of Google Play Service. My app should then work as-is once their fix is released.
For the record, I am using this in my tracker's XML file (res/xml/app_tracker_config.xml):
My getTracker() implementation:
Then in onCreate() for my home screen's activity I just do this to initialise GA:
EDIT (extra info): Global config file, res/xml/analytics_global_config.xml:
My app's manifest refers to this file in this child tag of the
application
element:Just add this in your manifest
After that you should start to receive in this logcat:
After restarting of application:
Currently in my project I'm using this code (in Application.onCreate() method), it works just fine:
Note:
Throwables
is class from guavaVariation without Guava but without full stacktrace, only original line number and method included into report:
Sorry for the offtopic, but since that problem I switched to using Crashlytics for error collecting and it is rather more effective, than GA.