Cobub Razor
Cobub Toaster
Other Links
Cobub Razor
Cobub Toaster
Other Links
This document is valid for Version 0.7 of Cobub Razor.
The goal of this document is to explain usage rules of Cobub Razor Android SDK for facilitating developers.
This document is for Android SDK developers, who use the Open Source Mobile Analytics – Cobub Razor.
Cobub Razor - The Open Source Mobile Analytics
First please setup the Web Server of Cobub Razor (instruction), then register App on web server and fill App info after login. Once App is created successfully, you could obtain AppKey.
Open android_sdk in the directory you uploaded on the server. Import android_sdk to Eclipse and export sdk jar file.
Eclipse users right click own project root directory and select Properties —>Java Build Path —>libraries. Then click Add External JARs and select path of com.wbkit1.0.jar. Finally, click OK and then import is completed.
Add AppKey obtained by App to meta-data of AndroidManifest.xml.
(Note: String must be ‘UMS_APPKEY‘)
Send user analytic data to server.
Obtain relevant status info of phone.
Obtain current user’s location info.
Visit Wi-Fi network status info.
Obtain recent running task info.
Read and write file to sdcard.
Read program error log.
Visit GSM network info.
The AndroidManifest.xml file as shown below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wbtech.test_sample" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.GET_TASKS"/> <uses-permission android:name="android.permission.READ_LOGS"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="UMS_APPKEY" android:value="bb08202a625c2b5cae5e2632f604352f "/> </application> </manifest>
* Add Reference
import com.wbtech.ums.UmsAgent;
* Init
Call UmsAgent.init(Context context, String url)in onCreate() method of App enter Activity, make sure that this method be called before other methods. The url parameter should be ended with "index.php?", like "http://demo.cobub.com/razor/index.php?".
* Obtain UserID
Call UmsAgent.bindUserid(Context context, String userID) method where you can obtain the unique identifier of user, and this method will record the userID on behalf of the user of using this application.
* Bind Tags
Call UmsAgent.postTags(final Context context, final String tags) method where you can obtain the attributes to tag the user. The tag values will be sent to server.
* Register Activity
Call UmsAgent.onResume(Context) in onResume method of every Activity. The passed parameter is the reference of current context. This method will read AppKey from AndroidManifest.xml automatically and record the time of user enters into this activity. Do not pass global application context.
protect void onResume(){ super.onResume(); UmsAgent.onResume(this); }
Call UmsAgent.onPause(Context) in onPause method of every Activity. Parameter is the reference of current context. This method will record the time of user leaves this activity.
protected void onPause(){ super.onPause(); UmsAgent.onPause(this); }
Call UmsAgent.postClientData(Context) in onCreate method of every Activity. Parameter is the reference of current context.
public void onCreate (Bundle savedInstanceState){ super.onCreata(savedInstanceState); setContentView(R.layout.main); UmsAgent.postClinetData(this); }
Code sample as shown below:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.button1); UmsAgent.init(this."http://demo.cobub.com/razor/index.php?"); UmsAgent.update(this); UmsAgent.setDefaultReportPolicy(this, SendPolicy.REALTIME); UmsAgent.bindUserid(this, "cobub.open@gmail.com"); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub UmsAgent.onEvent(MainActivity.this, "eventid"); UmsAgent.onEvent(MainActivity.this, "event_id", "label", 30.0); } }); }
We recommend you call UmsAgent.onResume() and UmsAgent.onPause() in all activities. If not, Page View report and some related reports will not be available on the Web Server.
Check to make sure that AppKey has been correctly written to Androidmanifest.xml.
Check to make sure that all required permissions have been added.
Check to make sure that all Activities have called onResume and onPause.
Check to make sure that test phone or simulator has successfully connected to network.
Android SDK could help you catch exit exception during App usage and send error report to server. Error report includes App version, OS version, device type and stacktrace of program exception. These data will help you debug App errors. We provide two ways to report error info. One is catched automatically by system and another is passed by developers.
For the former, you need to add android.permission.READ_LOGS permission in AndroidManifest.xml and call UmsAgent.onError(Context) in onCreate of Main Activity(App entry).
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); UmsAgent.onError(this); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); UmsAgent.onError(this); }
For the latter,developers need to call UmsAgent.onError(Context,String)and pass error info catched by their own to the second parameter. You can check that the log has been sent to the error analytics data statistics reports of my product.
Except basic data statistics analysis, the SDK also support analysis of custom event. For example, you could count ad clicks or times of video has been played. Here we provide several simple and common interfaces:
UmsAgent.onEvent(Context context,String event_id);
context: the reference of current context event_id: the ID of current statistics event, could not have spaces.
Invoke this API will send event info to the server and generate the event report on the server which analyzes sending times and changing trends corresponding to event_id, such as AD clicks, message numbers and so on. For example, to monitor AD clicks of App in MainActivtiy. Event ID is “ ad_click“. Once AD is clicked, you need call
UmsAgent.onEvent(MainActivity.this,“ad_click“)
in App to notify server that an AD click event has occurred.
UmsAgent.onEvent(Context context,String event_id,int acc)
For the frequent events, you can maintain a counter for them . In this way, event that are triggered by many times will just need generate one message. This message includes triggered times of this event. Here is overloaded two APIs:
UmsAgent.onEvent(Context context,String event_id,int acc) UmsAgent.onEvent(Context context,String event_id,String label,int acc)
acc : triggered times of corresponding event. In addition to the statistics of the number of events, here we can save and statistics the value of the label according to event_id.The overloaded methods are as follows:
UmsAgent.onEvent(Context context,String event_id,String label,double value)
For example, event_id represents an “ order “ event, then the label can be marked as an “ order number ”, and the value represents the value of the“ order number ”.
Cobub Android SDK provides the Debug function, which can help developers to locate problems. Developers can enable debug function and set the different log level:
UmsAgent.setDebugEnabled(true); UmsAgent.setDebugLevel(UmsAgent.LogLevel);
LogLevel has five levels:Info, Debug, Warn, Error, Verbose.
This function will help you push your new version App to users. You just need to modify VersionCode in AndroidManifest.xml and upload App APK to server.
android.permission.WRITE_EXTERNAL_STORAGE
Call UmsAgent.update(this) in onCreate() of App entry Activity when you want the APP to check that whether Web Server has a new version of the App automatically.
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); UmsAgent.update(this); }
In consideration of limitations of the user traffic, we now do automatic reminders under Wi-Fi intervention by default.
When updating App every time, you just need to modify VersionCode and upload App APK to server.
UmsAgent.update() will check that whether there is a new version App on server. It will notify user whether to ungrade SDK if there is a new App SDK. SDK wil upgrade after user choose to ungrade. (whether to ungrade according to version code)
5.1 Model Explaination
App only sends a message to server when it starts. All messages produced during App will be sent to server on next time start. If the App starts without network, then the messages will be stored in local and App will try to send next time.
Once App produces a message, sending it to server immediately.
5.2 Set sending model
Call UmsAgent.setDefaultReportPolicy(Context,int) in entry Activity. Parameter int could be 0 or 1.
1 stands for Real-time sending and 0 stands for Start sending.
UmsAgent.updateOnlineConfig(Context)
Invoke this API in onCreate() method of App's entey Activity and SDK will get your online configuration on the server and store this info in local.
You can also read your custom parameters by using following API:
UmsAgent.updateOnlineConfig(Context context,String key)
key: the key which has been defined on the web . A empty string will be returned if the corresponding value is not read.