5

我想在我的 android 应用程序中集成 Flurry 分析,它看起来非常简单。但我不熟悉乱舞和它是如何工作的。

我应该添加代码:

public void onStart()
{
super.onStart();
FlurryAgent.onStartSession(sample, “APIXXXXXXXXXXXX”);

}

在每一项活动中?

我的应用程序使用了很多活动,我并不关心跟踪使用了哪些活动,只关心安装数量、会话和会话长度。但是,如果只在启动活动中添加乱舞代码,会话长度是否可用?

我知道我想要的大部分信息已经在 Play 商店中可用,但我想尝试一下以了解不同平台上的应用程序。

4

2 回答 2

16

这是一个很好的答案:https ://stackoverflow.com/a/8062568/1635817

我建议你创建一个“BaseActivity”并告诉你所有的活动来扩展它,这样你就不必在每个活动类中复制/粘贴这些行。

像这样的东西:

public class BaseActivity extends Activity
{
    public void onStart()
    {
       super.onStart();
       FlurryAgent.onStartSession(this, "YOUR_KEY");
       // your code
    }

    public void onStop()
    {
       super.onStop();
       FlurryAgent.onEndSession(this);
       // your code
    }
}

回应@conor 评论:

来自Flurry 的文档

So long as there is any Context that has called onStartSession(Context, String) but not onEndSession(Context), the session will be continued. Also, if a new Context calls onStartSession(Context, String) within 10 seconds (the default session timeout length) of the last Context calling onEndSession, then the session will be resumed, instead of a new session being created. Session length, usage frequency, events and errors will continue to be tracked as part of the same session. This ensures that as a user transitions from one Activity to another in your application they will not have a separate session tracked for each Activity, but will have a single session that spans many activities.

于 2012-09-06T20:21:40.867 回答
4

Answer from florianmski has sense, but there are some problems when you have to use different kinds of activities in your application such as FragmentActivity, TabActivity, ListActivity and so on. In this case you are not able to extend all your activities from single BaseActivity. Personally I would prefer to put calls of onStartSession and onEndSession in each activity's onStart and onStop methods, but before wrap them into some class, for example:

public class Analytics {
    public static void startSession(Context context) {
        FlurryAgent.onStartSession(context, Config.FLURRY_KEY);
        // here could be some other analytics calls (google analytics, etc)
    }
    public static void stopSession(Context context) {
        FlurryAgent.onEndSession(context);
        // other analytics calls
    }
}

Inside each activity:

public void onStart() {
    super.onStart();
    Analytics.startSession(this);
}

public void onStop() {
    super.onStop()
    Analytics.stopSession(this);
}
于 2014-05-29T08:52:01.020 回答