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