简体   繁体   English

每个活动中的乱舞分析?

[英]Flurry analytics in every Activity?

I want to integrate flurry analytics in my android application, it looks really simple. 我想在我的Android应用程序中集成flurry分析,它看起来非常简单。 But i am not familiar with flurry and how it works. 但我不熟悉乱舞及其运作方式。

Should i add the code : 我应该添加代码:

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

}

in every activity? 在每个活动?

My application uses a lot of activities and i don't really care for tracking which of the activities is used, only the number of installations, sessions and session length. 我的应用程序使用了很多活动,我并不真正关心跟踪使用哪些活动,只关注安装次数,会话次数和会话长度。 But is the session length available if the flurry code is only added in the startup activity? 但是,如果仅在启动活动中添加了flurry代码,那么会话长度是否可用?

I know most of the information i want is available in play store already, but i want to try this to have an overview of applications on different platforms. 我知道我想要的大部分信息已经在Play商店中提供,但我想尝试这一点来概述不同平台上的应用程序。

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

I suggest you to create a "BaseActivity" and to tell all your activities to extend it so you don't have to copy/paste those lines in every activity class. 我建议你创建一个“BaseActivity”并告诉你所有的活动来扩展它,这样你就不必在每个活动类中复制/粘贴这些行。

Something like this : 像这样的东西:

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
    }
}

In response to @conor comment : 回应@conor评论:

From Flurry's documentation 来自Flurry的文档

So long as there is any Context that has called onStartSession(Context, String) but not onEndSession(Context), the session will be continued. 只要有任何上下文调用了onStartSession(Context,String)而不是onEndSession(Context),会话就会继续。 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. 此外,如果新的Context在最后一次调用onEndSession的Context的10秒内(默认会话超时长度)调用onStartSession(Context,String),则会恢复会话,而不是创建新会话。 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. 这可确保当用户在应用程序中从一个Activity转换到另一个Activity时,他们将不会为每个Activity跟踪单独的会话,但会有一个跨越许多活动的会话。

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. 来自florianmski的答案很有意义,但是当您必须在应用程序中使用不同类型的活动时会出现一些问题,例如FragmentActivity,TabActivity,ListActivity等。 In this case you are not able to extend all your activities from single BaseActivity. 在这种情况下,您无法从单个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: 我个人更喜欢在每个活动的onStart和onStop方法中调用onStartSession和onEndSession,但在将它们包装到某个类之前,例如:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM