Post-release statistics of Android applications-Baidu mobile statistics applications and android statistics
After an App is published to various channels, we need to collect some information from different channels, such as some abnormal information generated during app running, distribution of apps in various android versions, distribution of app versions, number of users in various channels, user loyalty, and other information. We can use Baidu mobile statistics to achieve this.
First, you must have an account for Baidu developers. Then, go to http://developer.baidu.com/lele#app/projectto create a project. We created a test project.
Click the test project to record the api key.
Click the Frontia service in the left-side menu to set the mobile statistics function.
The following page appears when you regret adding mobile statistics:
Copy the ReportID as a value for subsequent calls to this function. Click View statistics to view some statistics. Of course, there is nothing in the statistics. We have added the statistics function and there will be information here.
Then download the sdk
Add the program running permission
"Data-snippet-id =" ext. c5dfff1e9070a5fe2d6bc26b2cec8419 "data-snippet-saved =" false "data-csrftoken =" GxabGEAY-5dfNLFG1mwgVNd0SSDpHvDYnQ6k "data-codota-status =" done"
<! -- Public permissions of the Frontia framework --> <uses-permission android: name = "android. permission. INTERNET "/> <uses-permission android: name =" android. permission. ACCESS_WIFI_STATE "/> <uses-permission android: name =" android. permission. ACCESS_NETWORK_STATE "/> <uses-permission android: name =" android. permission. WRITE_EXTERNAL_STORAGE "/> <uses-permission android: name =" android. permission. READ_PHONE_STATE "/> <uses-permission android Oid: name = "android. permission. ACCESS_DOWNLOAD_MANAGER"/> <uses-permission android: name = "android. permission. DOWNLOAD_WITHOUT_NOTIFICATION"/> <! -- Permissions required by FrontiaPush and FrontiaStatistics --> <uses-permission android: name = "android. permission. WRITE_SETTINGS"> </uses-permission>
Implement a subclass of an Application to complete Initialization
public class App extends Application { @Override public void onCreate() { super.onCreate(); FrontiaApplication.initFrontiaApplication(getApplicationContext()); }}
Specify our application in the manifest file and change the package name to the package name of your project.
android:name=".app.App"
Compile a configuration class to declare some values used for the configuration.
Public class Config {public final static String APIKEY = "7jmaDS9xP0C56d44g0LLXCap"; public static final String REPORT_ID = "70f9ea11c5"; public static final String EVENT_ID = "1"; // event}
Write a base-class activity. In order to complete some UI statistics functions of all the activities, reuse the code.
Package cn.edu. zafu. channeldemo; import android. OS. bundle; import android. support. v7.app. appCompatActivity; import android. util. log; import com. baidu. frontia. frontia; import com. baidu. frontia. api. frontiaStatistics; import cn.edu. zafu. channeldemo. config. config;/*** User: lizhangqu (513163535@qq.com) * Date: 2015-07-04 * Time: */public class BaseActivity extends AppCompatActivity {private FrontiaStatistics mFrontiaStatistics; private static final String TAG = "BaseActivity"; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); boolean isInit = Frontia. init (this. getApplicationContext (), Config. APIKEY); Log. d (TAG, "initialization successful:" + isInit); mFrontiaStatistics = Frontia. getStatistics ();} public void onResume () {Log. w (TAG, "BaseActivity. onResume () "); super. onResume ();/*** page START (each Activity needs to be added. If this call has been added to an inherited parent Activity, it must not be added to the Child Activity) * cannot match StatService. onPageStart-level onPageEnd function cross-use */mFrontiaStatistics. pageviewStart (this, this. getClass (). getName ();} public void onPause () {super. onPause (); Log. w (TAG, "BaseActivity. onPause () ");/*** the end of the page (each Activity needs to be added. If this call has been added to an inherited parent Activity, the child Activity must not be added) * cannot match StatService. onPageStart-level onPageEnd function cross-use */mFrontiaStatistics. pageviewEnd (this, this. getClass (). getName ());}}
Compile the Activity to inherit the basic Activity class and use some statistical functions, such as exception statistics, Custom Event statistics, and log sending policy settings. For more information, see annotations.
Package cn.edu. zafu. channeldemo; import android. OS. bundle; import android. util. log; import android. view. view; import android. widget. button; import com. baidu. frontia. frontia; import com. baidu. frontia. api. frontiaStatistics; import cn.edu. zafu. channeldemo. config. config; import cn.edu. zafu. channeldemo. util. appUtil; public class MainActivity extends BaseActivity {private FrontiaStatistics mFrontiaStatistics; pr Ivate Button btnException; private Button btnEvent; private Button btnEventDuration; private Button btnEventStart; private Button btnEventEnd; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); mFrontiaStatistics = Frontia. getStatistics (); String channel = AppUtil. getMetaValue (this, "CHANNEL_NAME"); Log. d ("TAG", ch Annel); mFrontiaStatistics. setAppDistributionChannel (channel, true); // sets the application publishing channel mFrontiaStatistics. setSessionTimeout (50); // During the test, the session can expire in 1 second, so that a large number of logs will be generated during continuous start and exit. MFrontiaStatistics. enableExceptionLog (); // enable the exception log mFrontiaStatistics. setReportId (Config. REPORT_ID); // The reportId must be registered and generated on the mtj website. This setting can also be found in AndroidManifest. in xml, enter // The first parameter is the log sending policy // The second parameter is the log sending policy device's periodic sending // The third parameter is the log sending interval // The fourth parameter is whether send the log btnException = (Button) only in the case of wifi) findViewById (R. id. btn_excep); btnEvent = (Button) findViewById (R. id. btn_event); btnEventDuration = (Button) findViewById (R. id. btn_event_duration); B TnEventStart = (Button) findViewById (R. id. btn_event_start); btnEventEnd = (Button) findViewById (R. id. btn_event_end); btnException. setOnClickListener (new View. onClickListener () {public void onClick (View v) {// here 10/0, an exception occurs, used to verify the upload exception Log. d ("TAG", 10/0 + "") ;}}); btnEvent. setOnClickListener (new View. onClickListener () {public void onClick (View v) {FrontiaStatistics. event event = new FrontiaSta Tistics. event (Config. EVENT_ID, "Event 1"); mFrontiaStatistics. logEvent (event) ;}});/*** the first method of customizing an event, writing the duration of an event */btnEventDuration. setOnClickListener (new View. onClickListener () {public void onClick (View v) {FrontiaStatistics. event event = new FrontiaStatistics. event (Config. EVENT_ID, "event 1"); event. setDuration (100); // The event duration is 100 ms mFrontiaStatistics. logEventDuration (event) ;}}); // The second method of customizing an event: the duration of the event. Frontia rather than developers. Final FrontiaStatistics. event asyncEvent = new FrontiaStatistics. event (Config. EVENT_ID, "Event 1"); btnEventStart. setOnClickListener (new View. onClickListener () {public void onClick (View v) {mFrontiaStatistics. eventStart (asyncEvent) ;}}); // The second method of customizing an event. You can customize the start time and end time of the event btnEventEnd. setOnClickListener (new View. onClickListener () {public void onClick (View v) {mFrontiaStatistics. eventEnd (asyncEvent );}});}}
Add the id and name of our custom event to the statistics background
This is the case after adding
After that, you can generate a channel package and perform corresponding statistical functions. For more information about how to generate a channel package, see the previous blog post. Android Application release preparation: generate a channel package and apply for a channel. Android Application release preparation-channel registration and authentication
After that, you can use android studio to generate a channel package and publish the package to a specified channel. After installation, you can perform some statistical work, such as program exception logs, custom Event triggering times, duration, distribution of versions, and other information.
For more statistics, go to the background.
Download related source code
Http://download.csdn.net/detail/sbsujjbcy/8869821
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.