@OnClick(R.id.trackGoalButton) void onTrackGoalClicked(View view) { float revenue; try { revenue = Integer.valueOf( ((EditText) findViewById(R.id.goalTextEditView)).getText().toString() ); } catch (Exception e) { TrackHelper.track().exception(e).description("wrong revenue").with(getTracker()); revenue = 0; } TrackHelper.track().goal(1).revenue(revenue).with(getTracker()); }
@OnClick(R.id.raiseExceptionButton) void onRaiseExceptionClicked(View view) { TrackHelper.track().exception(new Exception("OnPurposeException")).description("Crash button").fatal(false).with(getTracker()); }
@Override public TrackMe build() { String className; try { StackTraceElement trace = mThrowable.getStackTrace()[0]; className = trace.getClassName() + "/" + trace.getMethodName() + ":" + trace.getLineNumber(); } catch (java.lang.Exception e) { Timber.tag(TAG).w(e, "Couldn't get stack info"); className = mThrowable.getClass().getName(); } String actionName = "exception/" + (mIsFatal ? "fatal/" : "") + (className + "/") + mDescription; return new TrackMe(getBaseTrackMe()) .set(QueryParams.ACTION_NAME, actionName) .set(QueryParams.EVENT_CATEGORY, "Exception") .set(QueryParams.EVENT_ACTION, className) .set(QueryParams.EVENT_NAME, mDescription) .set(QueryParams.EVENT_VALUE, mIsFatal ? 1 : 0); } }
@Override public void uncaughtException(Thread thread, Throwable ex) { try { String excInfo = ex.getMessage(); TrackHelper.track(mTrackMe).exception(ex).description(excInfo).fatal(true).with(getTracker()); // Immediately dispatch as the app might be dying after rethrowing the exception getTracker().dispatch(); } catch (Exception e) { Timber.tag(TAG).e(e, "Couldn't track uncaught exception"); } finally { // re-throw critical exception further to the os (important) if (getDefaultExceptionHandler() != null && getDefaultExceptionHandler() != this) { getDefaultExceptionHandler().uncaughtException(thread, ex); } } } }
@Override public void uncaughtException(Thread thread, Throwable ex) { try { String excInfo = ex.getMessage(); TrackHelper.track(mTrackMe).exception(ex).description(excInfo).fatal(true).with(getTracker()); // Immediately dispatch as the app might be dying after rethrowing the exception getTracker().dispatch(); } catch (Exception e) { Timber.tag(TAG).e(e, "Couldn't track uncaught exception"); } finally { // re-throw critical exception further to the os (important) if (getDefaultExceptionHandler() != null && getDefaultExceptionHandler() != this) { getDefaultExceptionHandler().uncaughtException(thread, ex); } } } }
@Override public TrackMe build() { String className; try { StackTraceElement trace = mThrowable.getStackTrace()[0]; className = trace.getClassName() + "/" + trace.getMethodName() + ":" + trace.getLineNumber(); } catch (java.lang.Exception e) { Timber.tag(TAG).w(e, "Couldn't get stack info"); className = mThrowable.getClass().getName(); } String actionName = "exception/" + (mIsFatal ? "fatal/" : "") + (className + "/") + mDescription; return new TrackMe(getBaseTrackMe()) .set(QueryParams.ACTION_NAME, actionName) .set(QueryParams.EVENT_CATEGORY, "Exception") .set(QueryParams.EVENT_ACTION, className) .set(QueryParams.EVENT_NAME, mDescription) .set(QueryParams.EVENT_VALUE, mIsFatal ? 1 : 0); } }
/** * 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. * <p> * This is just a different way to define an event. * Keep in mind Matomo is not a crash tracker, use this sparingly. * <p> * For this to be useful you should ensure that proguard does not remove all classnames and line numbers. * Also note that if this is used across different app versions and obfuscation is used, the same exception might be mapped to different obfuscated names by proguard. * This would mean the same exception (event) is tracked as different events by Matomo. * * @param throwable exception instance */ public Exception exception(Throwable throwable) { return new Exception(this, throwable); }
/** * 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. * <p> * This is just a different way to define an event. * Keep in mind Matomo is not a crash tracker, use this sparingly. * <p> * For this to be useful you should ensure that proguard does not remove all classnames and line numbers. * Also note that if this is used across different app versions and obfuscation is used, the same exception might be mapped to different obfuscated names by proguard. * This would mean the same exception (event) is tracked as different events by Matomo. * * @param throwable exception instance */ public Exception exception(Throwable throwable) { return new Exception(this, throwable); }
@Test public void testTrackException() throws Exception { Exception catchedException; try { throw new Exception("Test"); } catch (Exception e) { catchedException = e; } assertNotNull(catchedException); track().exception(catchedException).description("<Null> exception").fatal(false).with(mTracker); verify(mTracker).track(mCaptor.capture()); assertEquals(mCaptor.getValue().get(QueryParams.EVENT_CATEGORY), "Exception"); StackTraceElement traceElement = catchedException.getStackTrace()[0]; assertNotNull(traceElement); assertEquals(mCaptor.getValue().get(QueryParams.EVENT_ACTION), "org.matomo.sdk.extra.TrackHelperTest" + "/" + "testTrackException" + ":" + traceElement.getLineNumber()); assertEquals(mCaptor.getValue().get(QueryParams.EVENT_NAME), "<Null> exception"); }
@Test public void testTrackException() throws Exception { Exception catchedException; try { throw new Exception("Test"); } catch (Exception e) { catchedException = e; } assertNotNull(catchedException); track().exception(catchedException).description("<Null> exception").fatal(false).with(mTracker); verify(mTracker).track(mCaptor.capture()); assertEquals(mCaptor.getValue().get(QueryParams.EVENT_CATEGORY), "Exception"); StackTraceElement traceElement = catchedException.getStackTrace()[0]; assertNotNull(traceElement); assertEquals(mCaptor.getValue().get(QueryParams.EVENT_ACTION), "org.matomo.sdk.extra.TrackHelperTest" + "/" + "testTrackException" + ":" + traceElement.getLineNumber()); assertEquals(mCaptor.getValue().get(QueryParams.EVENT_NAME), "<Null> exception"); }
@OnClick(R.id.raiseExceptionButton) void onRaiseExceptionClicked(View view) { TrackHelper.track().exception(new Exception("OnPurposeException")).description("Crash button").fatal(false).with(getTracker()); }
@OnClick(R.id.trackGoalButton) void onTrackGoalClicked(View view) { float revenue; try { revenue = Integer.valueOf( ((EditText) findViewById(R.id.goalTextEditView)).getText().toString() ); } catch (Exception e) { TrackHelper.track().exception(e).description("wrong revenue").with(getTracker()); revenue = 0; } TrackHelper.track().goal(1).revenue(revenue).with(getTracker()); }