简体   繁体   中英

Flurry analytics in every Activity?

I want to integrate flurry analytics in my android application, it looks really simple. 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?

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.

Here is a great answer : 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.

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 :

From Flurry's documentation

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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