我正在开发一个android应用程序,它集成了MixPanel用于分析和BugSnag用于错误监视。
最近我们在应用程序中发现崩溃,由于找不到崩溃的根本原因,我们添加了代码,以便在出现错误时重新启动应用程序。除了重新启动,我们还开始跟踪bug发生的次数。我的偏好是同样使用bugsnag,但是团队中有几个人问为什么我们不能使用mixpanel,因为我们可以用发送到mixpanel的参数轻松过滤掉事件。但我觉得mixpanel不应该被用作跟踪用户事件的专用工具。无论是崩溃还是重启都不是因为用户事件,而是随机发生的。
我想听听社区对此的建议/想法。

最佳答案

您可以在Thread.setDefaultUncaughtExceptionHandler(...)中使用Application.onCreate来设置自定义Thread.UncaughtExceptionHandler,该自定义跟踪mixpanel所有未捕获的异常(崩溃),并设置如下属性:

public class MyExceptionHandler implements UncaughtExceptionHandler
{
    private UncaughtExceptionHandler defaultExceptionHandler;

    public MyExceptionHandler (UncaughtExceptionHandler defaultExceptionHandler)
    {
        this.defaultExceptionHandler = defaultExceptionHandler;
    }

    public void uncaughtException(Thread thread, Throwable exception)
    {
        mMixPanelInstance.trackEvent("APP_CRASH", null);
        if (defaultExceptionHandler != null)
        {
            defaultExceptionHandler.uncaughtException(thread, exception);
        }

    }
}


MyApplication.onCreate(...)
{
    UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler(currentHandler));
}

10-07 12:49
查看更多