Commit fb43345ff3e8c18b7987aa50cfaba46056ed58e3
0 parents
Exists in
master
branch release
Showing 19 changed files with 406 additions and 0 deletions Inline Diff
- .gitignore
- README
- TraceSDKSample/.classpath
- TraceSDKSample/.project
- TraceSDKSample/AndroidManifest.xml
- TraceSDKSample/libs/android-support-v4.jar
- TraceSDKSample/proguard-project.txt
- TraceSDKSample/project.properties
- TraceSDKSample/res/drawable-hdpi/ic_launcher.png
- TraceSDKSample/res/drawable-mdpi/ic_launcher.png
- TraceSDKSample/res/drawable-xhdpi/ic_launcher.png
- TraceSDKSample/res/layout/activity_main.xml
- TraceSDKSample/res/layout/fragment_main.xml
- TraceSDKSample/res/values-w820dp/dimens.xml
- TraceSDKSample/res/values/dimens.xml
- TraceSDKSample/res/values/strings.xml
- TraceSDKSample/res/values/styles.xml
- TraceSDKSample/src/com/mobithink/tracesdk/sample/MainActivity.java
- doc/integerate guide.md
.gitignore
File was created | 1 | /TraceSDK/bin | |
2 | /TraceSDK/gen | ||
3 | /TraceSDKSample/bin | ||
4 | /TraceSDKSample/gen |
README
TraceSDKSample/.classpath
File was created | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <classpath> | ||
3 | <classpathentry kind="src" path="src"/> | ||
4 | <classpathentry kind="src" path="gen"/> | ||
5 | <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> | ||
6 | <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> | ||
7 | <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> | ||
8 | <classpathentry kind="output" path="bin/classes"/> | ||
9 | </classpath> | ||
10 |
TraceSDKSample/.project
File was created | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <projectDescription> | ||
3 | <name>TraceSDKSample</name> | ||
4 | <comment></comment> | ||
5 | <projects> | ||
6 | </projects> | ||
7 | <buildSpec> | ||
8 | <buildCommand> | ||
9 | <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> | ||
10 | <arguments> | ||
11 | </arguments> | ||
12 | </buildCommand> | ||
13 | <buildCommand> | ||
14 | <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> | ||
15 | <arguments> | ||
16 | </arguments> | ||
17 | </buildCommand> | ||
18 | <buildCommand> | ||
19 | <name>org.eclipse.jdt.core.javabuilder</name> | ||
20 | <arguments> | ||
21 | </arguments> | ||
22 | </buildCommand> | ||
23 | <buildCommand> | ||
24 | <name>com.android.ide.eclipse.adt.ApkBuilder</name> | ||
25 | <arguments> | ||
26 | </arguments> | ||
27 | </buildCommand> | ||
28 | </buildSpec> | ||
29 | <natures> | ||
30 | <nature>com.android.ide.eclipse.adt.AndroidNature</nature> | ||
31 | <nature>org.eclipse.jdt.core.javanature</nature> | ||
32 | </natures> | ||
33 | </projectDescription> | ||
34 |
TraceSDKSample/AndroidManifest.xml
File was created | 1 | <?xml version="1.0" encoding="utf-8"?> | |
2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | package="com.mobithink.tracesdk.sample" | ||
4 | android:versionCode="1" | ||
5 | android:versionName="1.0" > | ||
6 | |||
7 | <uses-sdk | ||
8 | android:minSdkVersion="8" | ||
9 | android:targetSdkVersion="10" /> | ||
10 | <uses-permission android:name="android.permission.INTERNET"/> | ||
11 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | ||
12 | <uses-permission android:name="android.permission.READ_PHONE_STATE"/> | ||
13 | |||
14 | <application | ||
15 | android:allowBackup="true" | ||
16 | android:icon="@drawable/ic_launcher" | ||
17 | android:label="@string/app_name" | ||
18 | android:theme="@style/AppTheme" > | ||
19 | <activity | ||
20 | android:name="com.mobithink.tracesdk.sample.MainActivity" | ||
21 | android:label="@string/app_name" > | ||
22 | <intent-filter> | ||
23 | <action android:name="android.intent.action.MAIN" /> | ||
24 | |||
25 | <category android:name="android.intent.category.LAUNCHER" /> | ||
26 | </intent-filter> | ||
27 | </activity> | ||
28 | </application> | ||
29 | |||
30 | </manifest> | ||
31 |
TraceSDKSample/libs/android-support-v4.jar
No preview for this file type
TraceSDKSample/proguard-project.txt
File was created | 1 | # To enable ProGuard in your project, edit project.properties | |
2 | # to define the proguard.config property as described in that file. | ||
3 | # | ||
4 | # Add project specific ProGuard rules here. | ||
5 | # By default, the flags in this file are appended to flags specified | ||
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt | ||
7 | # You can edit the include path and order by changing the ProGuard | ||
8 | # include property in project.properties. | ||
9 | # | ||
10 | # For more details, see | ||
11 | # http://developer.android.com/guide/developing/tools/proguard.html | ||
12 | |||
13 | # Add any project specific keep options here: | ||
14 | |||
15 | # If your project uses WebView with JS, uncomment the following | ||
16 | # and specify the fully qualified class name to the JavaScript interface | ||
17 | # class: | ||
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
19 | # public *; | ||
20 | #} | ||
21 |
TraceSDKSample/project.properties
File was created | 1 | # This file is automatically generated by Android Tools. | |
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
3 | # | ||
4 | # This file must be checked in Version Control Systems. | ||
5 | # | ||
6 | # To customize properties used by the Ant build system edit | ||
7 | # "ant.properties", and override values to adapt the script to your | ||
8 | # project structure. | ||
9 | # | ||
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): | ||
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt | ||
12 | |||
13 | # Project target. | ||
14 | target=android-19 | ||
15 | android.library.reference.1=../TraceSDK | ||
16 |
TraceSDKSample/res/drawable-hdpi/ic_launcher.png
9.18 KB
TraceSDKSample/res/drawable-mdpi/ic_launcher.png
5.11 KB
TraceSDKSample/res/drawable-xhdpi/ic_launcher.png
14 KB
TraceSDKSample/res/layout/activity_main.xml
File was created | 1 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
2 | android:id="@+id/container" | ||
3 | android:layout_width="match_parent" | ||
4 | android:layout_height="match_parent" | ||
5 | android:gravity="center" | ||
6 | android:orientation="vertical" > | ||
7 | |||
8 | <Button | ||
9 | android:id="@+id/send" | ||
10 | android:layout_width="wrap_content" | ||
11 | android:layout_height="wrap_content" | ||
12 | android:text="Mark an event" /> | ||
13 | |||
14 | <Button | ||
15 | android:id="@+id/upgrade" | ||
16 | android:layout_width="wrap_content" | ||
17 | android:layout_height="wrap_content" | ||
18 | android:text="Level upgrade" /> | ||
19 | |||
20 | <Button | ||
21 | android:id="@+id/purchase" | ||
22 | android:layout_width="wrap_content" | ||
23 | android:layout_height="wrap_content" | ||
24 | android:text="Purchase" /> | ||
25 | |||
26 | </LinearLayout> |
TraceSDKSample/res/layout/fragment_main.xml
File was created | 1 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
2 | xmlns:tools="http://schemas.android.com/tools" | ||
3 | android:layout_width="match_parent" | ||
4 | android:layout_height="match_parent" | ||
5 | android:paddingBottom="@dimen/activity_vertical_margin" | ||
6 | android:paddingLeft="@dimen/activity_horizontal_margin" | ||
7 | android:paddingRight="@dimen/activity_horizontal_margin" | ||
8 | android:paddingTop="@dimen/activity_vertical_margin" | ||
9 | tools:context="com.mobithink.tracesdk.sample.MainActivity$PlaceholderFragment" > | ||
10 | |||
11 | <TextView | ||
12 | android:layout_width="wrap_content" | ||
13 | android:layout_height="wrap_content" | ||
14 | android:text="@string/hello_world" /> | ||
15 | |||
16 | </RelativeLayout> | ||
17 |
TraceSDKSample/res/values-w820dp/dimens.xml
File was created | 1 | <resources> | |
2 | |||
3 | <!-- | ||
4 | Example customization of dimensions originally defined in res/values/dimens.xml | ||
5 | (such as screen margins) for screens with more than 820dp of available width. This | ||
6 | would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). | ||
7 | --> | ||
8 | <dimen name="activity_horizontal_margin">64dp</dimen> | ||
9 | |||
10 | </resources> | ||
11 |
TraceSDKSample/res/values/dimens.xml
File was created | 1 | <resources> | |
2 | |||
3 | <!-- Default screen margins, per the Android Design guidelines. --> | ||
4 | <dimen name="activity_horizontal_margin">16dp</dimen> | ||
5 | <dimen name="activity_vertical_margin">16dp</dimen> | ||
6 | |||
7 | </resources> | ||
8 |
TraceSDKSample/res/values/strings.xml
File was created | 1 | <?xml version="1.0" encoding="utf-8"?> | |
2 | <resources> | ||
3 | |||
4 | <string name="app_name">TraceSDKSample</string> | ||
5 | <string name="hello_world">Hello world!</string> | ||
6 | <string name="action_settings">Settings</string> | ||
7 | |||
8 | </resources> | ||
9 |
TraceSDKSample/res/values/styles.xml
File was created | 1 | <resources> | |
2 | |||
3 | <!-- | ||
4 | Base application theme, dependent on API level. This theme is replaced | ||
5 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices. | ||
6 | --> | ||
7 | <style name="AppBaseTheme" > | ||
8 | <!-- | ||
9 | Theme customizations available in newer API levels can go in | ||
10 | res/values-vXX/styles.xml, while customizations related to | ||
11 | backward-compatibility can go here. | ||
12 | --> | ||
13 | </style> | ||
14 | |||
15 | <!-- Application theme. --> | ||
16 | <style name="AppTheme" parent="AppBaseTheme"> | ||
17 | <!-- All customizations that are NOT specific to a particular API-level can go here. --> | ||
18 | </style> | ||
19 | |||
20 | </resources> | ||
21 |
TraceSDKSample/src/com/mobithink/tracesdk/sample/MainActivity.java
File was created | 1 | package com.mobithink.tracesdk.sample; | |
2 | |||
3 | import java.util.HashMap; | ||
4 | import java.util.Map; | ||
5 | |||
6 | import com.mobithink.tracesdk.TraceAgent; | ||
7 | |||
8 | import android.os.Bundle; | ||
9 | import android.support.v4.app.FragmentActivity; | ||
10 | import android.view.View; | ||
11 | import android.view.View.OnClickListener; | ||
12 | import android.widget.Button; | ||
13 | |||
14 | public class MainActivity extends FragmentActivity { | ||
15 | |||
16 | @Override | ||
17 | protected void onCreate(Bundle savedInstanceState) { | ||
18 | super.onCreate(savedInstanceState); | ||
19 | setContentView(R.layout.activity_main); | ||
20 | TraceAgent.active(MainActivity.this, "5486"); | ||
21 | Button btnEvent = (Button) findViewById(R.id.send); | ||
22 | Button btnUp = (Button) findViewById(R.id.upgrade); | ||
23 | Button btnPurchase = (Button) findViewById(R.id.purchase); | ||
24 | btnEvent.setOnClickListener(listener); | ||
25 | btnUp.setOnClickListener(listener); | ||
26 | btnPurchase.setOnClickListener(listener); | ||
27 | } | ||
28 | |||
29 | @Override | ||
30 | protected void onPause() { | ||
31 | TraceAgent.onPause(this); | ||
32 | super.onPause(); | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | protected void onResume() { | ||
37 | TraceAgent.onResume(this); | ||
38 | super.onResume(); | ||
39 | } | ||
40 | |||
41 | OnClickListener listener = new OnClickListener() { | ||
42 | |||
43 | @Override | ||
44 | public void onClick(View v) { | ||
45 | switch (v.getId()) { | ||
46 | case R.id.send: | ||
47 | TraceAgent.onEvent(getApplicationContext(), "one test event"); | ||
48 | break; | ||
49 | case R.id.purchase: | ||
50 | Map<String, String> params = new HashMap<String, String>(); | ||
51 | params.put("amount", "10.5"); | ||
52 | params.put("currency", "USD"); | ||
53 | TraceAgent.onEvent(getApplicationContext(), "purchase", params); | ||
54 | break; | ||
55 | case R.id.upgrade: | ||
56 | TraceAgent.onEvent(getApplicationContext(), "upgrade", "11"); | ||
57 | break; | ||
58 | } | ||
59 | } | ||
60 | }; | ||
61 | } | ||
62 |
doc/integerate guide.md
File was created | 1 | Mobithink App Tracking SDK | |
2 | 2014-11 | ||
3 | |||
4 | 开发者接入指南 1.0.0 | ||
5 | 最后修订:2014-11-20 | ||
6 | |||
7 | # 一、 综述 | ||
8 | 1. 适用范围 | ||
9 | Mobithink App Tracking SDK(以下简称SDK)为移动应用提供数据统计分析服务,通过在应用中加入数 | ||
10 | 据SDK,来在Mobithink提供的网站中查阅应用的相关数据。 | ||
11 | 该SDK适用于 Android 1.6(API Level 4)及以上的设备。 | ||
12 | 2. 统计标准 | ||
13 | 数据系统中的基本数据单元依据以下标准定义: | ||
14 | Ø 新增用户 | ||
15 | Mobithink数据系统中的“用户”指用户的一台唯一设备。 | ||
16 | Ø 用户的一次使用 | ||
17 | 指用户从打开应用的界面至离开界面的完整过程。如用户在离开界面后10秒 | ||
18 | 内重新回到应用中,将被认为是上次使用被打扰后的延续,记为一次完整使用。 | ||
19 | Ø 页面 | ||
20 | 指Android应用的每个Activity。 | ||
21 | Ø 自定义事件 | ||
22 | 指用户在应用中进行了特定的操作或达成了特定的条件。例如:用户点击了广 | ||
23 | 告栏、用户进行付费等。 | ||
24 | 自定义事件用于收集任意您期望跟踪的数据。 | ||
25 | |||
26 | # 二、 接入数据系统 | ||
27 | 1. 为应用申请OfferID | ||
28 | 向Mobithink索取,用于唯一标识您的一款应用。 | ||
29 | 2. 向工程中导入追踪SDK | ||
30 | 下载数据统计SDK后解压至本地目录,将其中的TraceSDK.jar 导入 | ||
31 | 至您的工程中; | ||
32 | 在Eclipse中(其他开发工具参阅其自带说明)右键点击工程根目录→选择 | ||
33 | Properties --> Java Build Path --> Libraries → 点击Add External JARs…找 | ||
34 | 到本地目录下的TraceSDK.jar 文件,点击 打开按钮 即导入成功。 | ||
35 | 3. 配置ANDROIDMANIFEST.XML文件 | ||
36 | 应用需要的权限 用途 | ||
37 | INTERNET 允许程序联网和发送统计数据的权限。 | ||
38 | ACCESS_NETWORK_STATE 允许应用检测网络连接状态,在网络异常状态下避免数据发送,节省流量和电量。 | ||
39 | READ_PHONE_STATE 允许应用以只读的方式访问手机设备的信息,通过获取的信息来唯一标识用户。 | ||
40 | ACCESS_WIFI_STATE 获取设备的MAC地址,同样用来标识唯一用户。 | ||
41 | WRITE_EXTERNAL_STORAGE 用于保存设备信息,以及记录日志。 | ||
42 | |||
43 | 示例代码: | ||
44 | |||
45 | <?xml version="1.0" encoding="utf-8"?> | ||
46 | <manifest ......> | ||
47 | <uses-permission android:name="android.permission.INTERNET"/> | ||
48 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
49 | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
50 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
51 | |||
52 | <application ......> | ||
53 | <activity ......> | ||
54 | ...... | ||
55 | </activity> | ||
56 | ...... | ||
57 | |||
58 | </application> | ||
59 | </manifest> | ||
60 | |||
61 | 4. 添加SDK初始化代码 | ||
62 | 在应用启动的时候(比如在启动应用的activity的onCreate方法中)调用以下方法: | ||
63 | |||
64 | TraceAgent.active(Activity, offerId); | ||
65 | 5. 添加必须的调用方法 | ||
66 | 使用数据统计系统需要至少添加以下调用方法,这些调用用于准确跟踪用户每次的应用使用,是准确统计启动、活跃、留存数据的基础: | ||
67 | Ø 在应用的每个Activity的onResume方法里调用TraceAgent.onResume(Activity context),传入的参数为当前Activity实例,用于跟踪用户使用中的打开应用和页面跳转的数据。 | ||
68 | |||
69 | @Override | ||
70 | protect void onResume() { | ||
71 | super.onResume(); | ||
72 | TraceAgent.onResume(this); | ||
73 | } | ||
74 | Ø 在应用的每个Activity中的onPause方法里调用TraceAgent.onPause(Activity context),传入的参数为当前的Activity实例,用于跟踪用户离开页面和退出应用的数据。 | ||
75 | |||
76 | @Override | ||
77 | protect void onPause() { | ||
78 | super.onPause(); | ||
79 | TraceAgent.onPause(this); | ||
80 | } | ||
81 | |||
82 | 注意1:确保在每个activity中都调用了以上方法,否则可能造成应用的使用时长、页面访问时长数据错误。 | ||
83 | 注意2:对有继承关系的Activity,只需要对上层Activity基类添加调用即可,否则可能会重复计量,造成数据错误。 | ||
84 | 注意3:对于会内嵌其他Activity的ActivityGroup(比如TabActivity),建议不要在ActivityGroup里添加调用,而是在所有内嵌的Activity里添加。 | ||
85 | 注意4:如果应用只支持API Level 14以上的设备,可只在应用的入口Activity添加调用. | ||
86 | |||
87 | 6. 使用自定义事件 | ||
88 | 用法说明 | ||
89 | 自定义事件用于统计任何您期望去跟踪的数据,如:点击某功能按钮、填写某个输 | ||
90 | 入框、触发了某个广告等;同时,自定义事件还支持添加一些描述性的属性参数, | ||
91 | 使用多对Key-Value的方式来进行发送(非必须使用),用来对事件发生时的状 | ||
92 | 况做详尽分析。 | ||
93 | Ø 格式:32个字符以内的中文、英文、数字、下划线,注意eventId中不要加 | ||
94 | 空格或其他的转义字符。 | ||
95 | Ø 最多支持100个不同的Event ID。 | ||
96 | 如果您要跟踪更多的事件,我们提供了Label参数的用法,可 以 给 多 个 要 跟 踪 | ||
97 | 的同类型或类似的事件使用相同的Event ID,通过给他们分配不同Label来 | ||
98 | 达到区分跟踪多个事件的目的。这可理解为Event ID成为了多个事件的目录, | ||
99 | EventID+Label形成了一个具体事件。请对事件做好分类,这也对您管理和 | ||
100 | 查阅事件数据有利。 | ||
101 | 调用方法 | ||
102 | Ø 在应用程序要跟踪的事件处加入下面格式的代码,也就成功的添加了一个简单 | ||
103 | 事件到您的应用程序中了: | ||
104 | |||
105 | TraceAgent.onEvent(Context ctx, String EVENT_ID); | ||
106 | Ø 跟踪多个同类型事件,无需定义多个Event ID,可以使用Event ID做为目录 | ||
107 | 名,而使用Label标签来区分这些事件,可按照下面格式添加代码: | ||
108 | |||
109 | TraceAgent.onEvent(Context ctx, String EVENT_ID, String EVENT_LABEL); | ||
110 | Ø 为事件添加详尽的描述信息,可以更有效的对事件触发的条件和场景做分析, | ||
111 | 可按照下面格式添加代码: | ||
112 | |||
113 | TraceAgent.onEvent(Context ctx, String EVENT_ID, Map<String, Object> kv); | ||
114 | 注: 此Map的Value仅支持字符串(String)类型,其 | ||
115 | 他类型会自动调用toString()方法转换为String进行处理。每一次事件数据支 | ||
116 | 持10对不同参数传入。在Value使用String格式时,报表中将给出事件发 | ||
117 | 生时每种value出现的频次 | ||
118 | 示例1: | ||
119 | 跟踪某电商应用中首页的5个不同推广位置的点击次数,并收集宣传品的品类、 | ||
120 | 促销价格等信息: | ||
121 | // 可定义eventId=点击首页推荐位;event_LABEL=具体的位置编号 | ||
122 | |||
123 | @Override | ||
124 | public void onClick(View v) { | ||
125 | Map<String, Object> kv = new HashMap<String, Object>(); | ||
126 | kv.put("商品类型", "休闲食品"); | ||
127 | kv.put("价格","5~10元" ); | ||
128 | TraceAgent.onEvent(DemoActivity.this, "点击首页推荐位", kv); | ||
129 | } | ||
130 | • 注1:这 里 追 踪 的 事 件属于同类型,使用了Label标签的用法。以相同Event | ||
131 | ID来作为统一名称,Label来确定不同位置。这样查阅Event ID数据即 | ||
132 | 可了解全部推广位总量点击数据,展开Label可查阅具体某位置数据。 | ||
133 | • 注2:在value取值较离散情况下(如示例中收集的促销价格信息),不 | ||
134 | 要直接填充具体数值,而应划分区间后传入(如9.9元,可定义5~10元 | ||
135 | 的价格区间,传入5~10元),否则value不同取值很可能超过平台最 | ||
136 | 大数目限制,离散数据也对分析人员阅览数据造成影响。 | ||
137 | 示例2: | ||
138 | 在一款休闲游戏中记录玩家在各关卡中的失败数据,并收集玩家具体信息。 | ||
139 | // 可定义eventId=战斗失败 | ||
140 | |||
141 | Map<String, Object> kv = new HashMap<String, Object>(); | ||
142 | kv.put("等级", “20-30”); //级别区间,注意是字符串 | ||
143 | kv.put("关卡类别", “星空神域”); //关卡的大类别 | ||
144 | kv.put("关卡号", “第5关”); //关卡具体编号 | ||
145 | kv.put("失败原因", “主动退出”); //失败原因 | ||
146 | kv.put("该局分数", “10000~12000”); //玩家该局所打分数 | ||
147 | TCAgent.onEvent(DemoActivity.this, "战斗失败", kv); |