server端安装及配置
apache2 + Mysql5.7 + php7 + redis
参见:http://docs.cobub.com/pages/viewpage.action?pageId=884864
可能需要额外安装:
apt-get install php-mysqlnd
apt-get install php-mbstring
安装完成后创建新的App并获取其app key。
其它注意点
安装razor之前需要先配置sql_mode,set @@SET sql_mode='',否则会有时间格式问题和only_full_groupby的异常(存储过程报错)。
- 可选配置redis,配置后将enable实时分析功能。
| If you want to use Redis to improve the performance. Config redis to 1
| 0 = Disable Redis
| 1 = Enable Redis
|
*/
$config['redis'] = 1;
sdk编译及使用
gtihub:https://github.com/cobub/razor
其中sdk文件夹下包含了android和ios的sdk。例如将android sdk导入到Android Studio,可能需要修改gradle的版本号(4.2)。打包成class.jar文件。
android app埋点
新建android程序,将上述class.jar文件添加到工程中(参见http://blog.csdn.net/zhw1551706847/article/details/77709142 中的方法三)
对新版的android需要申请各种用户权限,直接在manifest.xml文件中配置将不起作用。
实例代码如下:
package com.example.razor.razor;
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.wbtech.ums.UmsAgent;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
verifyStoragePermissions(this);
setContentView(R.layout.activity_main);
UmsAgent.init(this, "http://192.168.32.120/razor/web/index.php?/ums", "eda4111e55727445fe2801712abcbe4a");
UmsAgent.setDebugEnabled(true);
UmsAgent.update(this);
UmsAgent.updateOnlineConfig(this);
UmsAgent.postTags(this, "test tags");
UmsAgent.setDefaultReportPolicy(this, UmsAgent.SendPolicy.POST_NOW);
String errorinfo = "PasswordErrorException: \n\t错误信息 at com.wbtech.test_sample.CobubSampleActivity";
UmsAgent.onError(this, "PasswordErrorException", errorinfo);
System.out.println(errorinfo);
UmsAgent.onEvent(this, "gywm_GD");
UmsAgent.onEvent(this, "wdyy_YH");
UmsAgent.onEvent(this, "jrzs_GD");
UmsAgent.onEvent(this, "lxwm_GD");
UmsAgent.onEvent(this, "DLYSJ_YH");
View butt = findViewById(R.id.button_error);
butt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
UmsAgent.onEvent(MainActivity.this, "eventid");
}
});
}
private static String[] PERMISSIONS_ = {
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.GET_TASKS,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_LOGS,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
};
public static void verifyStoragePermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_,
1
);
}
}
@Override
protected void onResume() {
super.onResume();
UmsAgent.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
UmsAgent.onPause(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
踩过的坑
- mysql5.7需要在安装之前配置sql_mode,否则安装会出错,执行定时任务存储过程也会出错;
- 埋点的app上传数据不成功,sdk中init函数调用后应当能够在clientdata中看到数据,如果没有看到,则有异常。
以上示例代码在运行后应该在服务端看到的日志如下,如果都是返回200则正常。(可以结合access.log和android端的logcat定位异常)
192.168.32.50 - - [19/Mar/2018:13:24:44 +0800] "POST /razor/web/index.php?/ums/usinglog HTTP/1.1" 200 225 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:44 +0800] "POST /razor/web/index.php?/ums/clientdata HTTP/1.1" 200 225 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:44 +0800] "POST /razor/web/index.php?/ums/appupdate HTTP/1.1" 200 325 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:44 +0800] "POST /razor/web/index.php?/ums/pushpolicyquery HTTP/1.1" 200 426 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:44 +0800] "POST /razor/web/index.php?/ums/tag HTTP/1.1" 200 225 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:44 +0800] "POST /razor/web/index.php?/ums/errorlog HTTP/1.1" 200 225 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:45 +0800] "POST /razor/web/index.php?/ums/eventlog HTTP/1.1" 200 225 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:45 +0800] "POST /razor/web/index.php?/ums/eventlog HTTP/1.1" 200 225 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:45 +0800] "POST /razor/web/index.php?/ums/eventlog HTTP/1.1" 200 225 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:45 +0800] "POST /razor/web/index.php?/ums/eventlog HTTP/1.1" 200 225 "-" "-"
192.168.32.50 - - [19/Mar/2018:13:24:45 +0800] "POST /razor/web/index.php?/ums/eventlog HTTP/1.1" 200 225 "-" "-"
- 一些bug比较难定位,可以从application/logs/log-xxxx-xx-xx.php入手