Android-Flurry统计: Flurry官方地址: https://developer.yahoo.com/ Flurry登录地址: https://login.flurry.com/ 前言: Flurry是国外一家专门为移动应用提供数据统计和分析的公司。他们的数据统计分析SDK支持的平台包括iPhone, iPad, Android, Windows Phone, Java ME和BlackBerry。使用Flurry服务的公司包括eBay、Yahoo、Hulu和Skype等超过11万家公司,涉及的应用超过36万个。
利用Flurry提供的分析平台,我们可以很容易地自动统计出应用的使用情况,例如:
1、每天(每周或每月)登录用户数,应用使用次数 2、每天(每周或每月)新用户数,活跃用户数 3、用户的所在地、年龄、性别的分布情况 等…….. 个人推荐: 国内用友盟统计 国外就Flurry:其中的一个理由就是Flurry不会被墙!
Flurry:集成地址: https://developer.yahoo.com/flurry/docs/integrateflurry/android/ 先决条件:Android API等级10及以上。
创建应用地址: https://y.flurry.com/admin/applications 创建步骤:如图: 说明:App name:这里可以自己随意填写(和包名没有关系);只要是自己明白就可以了。 其他步骤一直点下去就可以了。最终: 点击:Ok,got it! 这个时候就申请Key成功了 copy一份API Key(AppKey) 便于后面程序中用到。
在App项目–>build.gradle中添加:
// In your main app's Gradle config file: repositories { jcenter() } dependencies { // Required for Flurry Analytics integration // Flurry Analytics集成所需的 compile 'com.flurry.android:analytics:7.0.0@aar' // Optional - If you want to use the Ads SDK //可选 - 如果要使用Ads SDK :广告SDK compile 'com.flurry.android:ads:7.0.0@aar' }重要: 强烈建议您使用Flurry SDK的AAR格式。现在不推荐使用jar。请更新为AAR,因为Flurry将在以后的版本中删除jar。 注意: 如果要添加Flurry依赖项的AAR格式,则不需要修改AndroidManifest文件或ProGuard配置。
以下是AndroidManifest.xml为Flurry Analytics和Flurry广告配置的文件示例。
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.flurry.sample" android:versionCode="1" android:versionName="1.0" > <!-- Required permissions - 必要的权限 --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/app_icon" android:label="@string/app_name" android:theme="@style/AppTheme" > <!-- Required Activities if using Flurry Advertising 使用Flurry广告必要--> <activity android:name="com.flurry.android.FlurryFullscreenTakeoverActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode| screenSize|smallestScreenSize"> </activity> </application> </manifest>官方原文: Add the following calls to initialize the Flurry SDK by using the FlurryAgent.Builder to initialize the Flurry SDK with your project’s API key. If you are shipping an app, use the FlurryAgent Builder to init the SDK, passing it a reference to your Application Context and your project’s API key: 简单来说就是在上下文中添加初始化操作:Application类中
public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); new FlurryAgent.Builder() .withLogEnabled(true) .build(this, FLURRY_API_KEY); } }注意:6.0的Flurry版本的初始化 函数是 init(..);也是个人之前用的一个版本:如:
FlurryAgent.init(this, FLURRY_API_KEY);//flurry统计初始化But: It is safe to call the Builder more than once, provided that you use the same API key throughout the application. You may use any type of Context you wish. The following methods are now deprecated: setFlurryAgentListener(), setLogEnabled(), setLogLevel(), setContinueSessionMillis(), setCaptureUncaughtExceptions(), setPulseEnabled() and init(). 意思就是说:现在新版本不推荐使用以下方法了: setFlurryAgentListener(),setLogEnabled(),setLogLevel(),setContinueSessionMillis(),setCaptureUncaughtExceptions(),setPulseEnabled()和init()。
官方原文:(可以不看—-) 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 1 and 2. If you are instrumenting another type of Context, such as a Service, or your minimum target is Gingerbread, proceed with steps 1 or 2.
If your app is targeting Gingerbread or Honeycomb(API 10 -13), follow these steps:
Insert a call to FlurryAgent.onStartSession(Context) in your Activity’s onStart() method passing it a reference to a Context object (such as an Activity or Service). Do not pass in the global Application context. 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.
Insert a call to FlurryAgent.onEndSession(Context) in your Activity’s onStop() method. Do not pass in the global Application context. 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.
As long as there is any Context that has called onStartSession but not onEndSession, the session will be continued. Also, if a new Context calls onStartSession within 10 seconds 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 that they will not have a separate session tracked for each Activity, but will have a single session that spans many activities. If you want to track Activity usage, we recommend using logEvent, described below. 个人认为就办了一个事情就是 在Activity中添加操作Flurry的事件: 就是在所有Activity中:成对的onStart()和onStop()中分别添加: onStart:
FlurryAgent.setCaptureUncaughtExceptions(true);//这个看个人需要 FlurryAgent.onStartSession(this, FLURRY_API_KEY);onStop:
FlurryAgent.onEndSession(this);添加完成就是这种的了:
@Override protected void onStart() { super.onStart(); FlurryAgent.setCaptureUncaughtExceptions(true);//这个看个人需要 FlurryAgent.onStartSession(this, FLURRY_API_KEY); } @Override protected void onStop() { super.onStop(); FlurryAgent.onEndSession(this); }OK到这里基本就集成完成了; 就可以实现 Flurry的统计新增、日活等操作了。
说明:个人用的版本是:FlurryAnalytics-6.2.0的架包:
申请AppKey–>获取AppKey:这里就不说了
基础统计jar: FlurryAnalytics-6.2.0.jar 广告jar(个人没用):FlurryAds-6.2.0 下载[FlurryAnalytics-6.2.0的架包] 添加到项目:libs文件中–>选中右键–>Add As Library…
1:定义一个全局的静态类TestConstant.java(是否用静态类个人随意): 把AppKey 定义在这个类里面:如
public static String flurryKey = "自己的AppKey";// flurry统计key2:在全局类(TestApplication.java)中的OnCreate()中初始化 AppKey: 如:
FlurryAgent.setLogEnabled(false);//TJ:统计日志是否开启 FlurryAgent.init(this, TestConstant.flurryKey);//flurry统计初始化3:Activity 中使用统计添加代码:
添加代码: @Override protected void onStart() { super.onStart(); FlurryAgent.setCaptureUncaughtExceptions(true); FlurryAgent.onStartSession(this, TestConstant.flurryKey); } @Override protected void onStop() { super.onStop(); FlurryAgent.onEndSession(this); }将以下说明添加到您的proguard.cfg文件中:
# Required to preserve the Flurry SDK -keep class com.flurry.** { *; } -dontwarn com.flurry.** -keepattributes *Annotation*,EnclosingMethod,Signature -keepclasseswithmembers class * { public (android.content.Context, android.util.AttributeSet, int); } # Google Play Services library -keep class * extends java.util.ListResourceBundle { protected Object[ ][ ] getContents(); } -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { public static final *** NULL; } -keepnames @com.google.android.gms.common.annotation.KeepName class * -keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; } -keepnames class * implements android.os.Parcelable { public static final ** CREATOR; }OK到这里基本就能实现 Flurry统计的 新增、日活 等统计了。 举例子:新增/日活的查看方式如图: NEW DEVICES:就是对于日期对于的 新增 ACTIVE DEVICES/DAY:就是对于日期对于的 活跃设备 是不是很简单。
说明: 1:Flurry和友盟一样也是通过设备唯一ID判断数据的。 2:Flurry统计一般是有延迟的;个人测试发现延迟最大可能有6-8个小时; 所以:个人一般看数据都是凌晨后看前一天的数据。
OK后续会持续完善学习内容: A:flurry统计 : 个人认为国际上相对好用的统计,O(∩_∩)O哈哈~ B:友盟统计:国内比较强大且好用的统计。 C:极光推送: 主要推送功能比较完善简单。 D:个推: 一个统计。 E:51.la: 针对IP(web页面)统计的一个统计:添加前需要页面支持。 F:CNZZ : 很早和友盟合并了;导致友盟叫:友盟+;不错O(∩_∩)O哈哈~ 等…