FLURRY 文档摘要及备注

本文指导您如何在Android应用中配置Flurry Analytics,包括添加必要的库、配置AndroidManifest.xml、初始化FlurryAgent、启动和结束会话的方法,以及报告额外数据的功能。详细步骤确保您的应用能够有效收集并发送数据回Flurry服务器。

1)、Add the FlurryAnalytics_5.6.0.jar file to your classpath.
2)、Configure AndroidManifest.xml

    a). android.permission.INTERNET
        Required to send analytics data back to the flurry servers
    b). android.permission.ACCESS_NETWORK_STATE
        If your application has network state permissions, transmission of analytics data can be optimized.
    c). android.permission.ACCESS_COARSE_LOCATION 
            or
        android.permission.ACCESS_FINE_LOCATION

3)、Add calls to init, onStartSession and onEndSession

1、  If you are shipping an app, Insert a call to FlurryAgent.init(Context, String) in your class, passing it a reference to your Application Context and your project's API key:
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // configure Flurry
        FlurryAgent.setLogEnabled(false// init Flurry
        FlurryAgent.init(this, MY_FLURRY_APIKEY);
    }
}
    2、  If you are writing an app and the minimum target is Ice Cream Sandwich or above (minSdkVersion is set to API level 14 or greater), session handling is completely automatic and you may skip steps 3 and 4. If you are instrumenting another type of Context, such as a Service, or your minimum target is Gingerbread, proceed with steps 3 or 4.
    3、Insert a call to FlurryAgent.onStartSession(Context), passing it a reference to a Context object (such as an Activity or Service). If you are targeting Gingerbread, we recommend using the onStart method of each Activity in your application, and passing the Activity itself as the Context object. For services (or other Contexts), use the Service or the relevant Context as the Context object. Do not pass in the global Application context.
    4、Insert a call to FlurryAgent.onEndSession(Context) when a session is complete. If you are targeting Gingerbread, we recommend using the onStop method of each Activity in your application. For services (or other Contexts), ensure that onStop is called in each instrumented Service. Make sure to match up a call to onEndSession for each call of onStartSession, passing in the same  Context object that was used to call onStartSession. Do not pass in the global Application context.

You’re done! That’s all you need to do to begin receiving basic metric data.

3)、Optional Features

    **Report Additional Data**
    You can use the following methods (during a session only) to report additional data:
FlurryAgent.logEvent(String eventId)
FlurryAgent.logEvent(String eventId, boolean timed)
FlurryAgent.logEvent(String eventId, Map<String, String> parameters)
FlurryAgent.logEvent(String eventId, Map<String, String> parameters, boolean
timed)

Use FlurryAgent.logEvent to track user events that happen during a session. You can track how many times each event occurs, what order events happen in, how long events are, as well as what the most common parameters are for each event. This can be useful for measuring how often users take various actions, or what sequences of actions they usually perform. Each project supports a maximum of 300 event names, and each event id, parameter key, and parameter value must be no more than 255 characters in length. Each event can have no more than 10 parameters. The parameter argument is optional, and may be null. Each session can log up to 200 events and up to 100 unique event names.

FlurryAgent.endTimedEvent(String eventId)
FlurryAgent.endTimedEvent(String eventId, Map<String, String> parameters)

Timed event can be logged using FlurryAgent.logEvent. Use endTimedEvent to end the timed event.

4)、备注
以上就完成了 Fulrry 的配置过程,在项目中的代码是长这样的。
启动关闭代码

    public void onStart()  
    {  
       super.onStart();  
       FlurryAgent.onStartSession(this, STR_YOUR_API_KEY);  
       // your code  
    }  
    public void onStart()  
    {  
       super.onStart();  
       FlurryAgent.onStartSession(this, STR_YOUR_API_KEY);  
       // your code  
    }  

简单的可以在你的Activity的onStart()和onStop()方法中添加如上代码。
按照以上步骤就可以开始最基础的flurry测试了。运行完程序后一般需等待一定时间(目前来看只有前一天的数据)来在网页上看到数据的更新。
另外Flurry还可以记录你的一些事件信息。使用的函数如下:

logEvent (String eventId)
logEvent (String eventId, Map< String, String > parameters)
logEvent (String eventId, boolean timed)

eventId是自己随便定义的。就是相当于为你追踪的这个事件取个名字。
特别的,如果需要检测具体事件的响应时间(比如某个按钮事件),需要注意logEvent (String eventId, boolean timed),将timed参数设为true就可以记录这个event的开始执行时间,然后在你的代码中你认为事件完成的地方再调用endTimedEvent (String eventId)。这样会记录事件的整个执行时间。不过需要注意,经过我到目前的研究,不管是通过查看Analytics的分析页面,还是通过API直接获取数据。都得不到单个事件每一次执行的时间。只能得到平均(average),总体(total)。就是你这个事件执行了N次,它算N次的平均执行时间和N次相加的全部执行时间。
参考代码:

    case R.id.calllog_settings:  
            FlurryAgent.logEvent("calllog_settings", true);                      
            SettingsLauncher.launch(this);  

            FlurryAgent.endTimedEvent("calllog_settings");  
         return true;  

Android API Document:

http://support.flurry.com/index.php?title=Analytics/Code/Doc/Android

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值