Android apps add allies statistics and calculations new users

Source: Internet
Author: User
Tags exit in inheritance

Hardware and Software Environment
Macbook Pro MGX 72
Android Studio 1.3.2
Genymotion Simulator


Integrated friend of the Alliance SDK

First to the league's official website http://www.umeng.com/registered account, completed to the admin back to add the need to integrate the application of the Alliance statistics, as follows

After submitting, assign key to your application, as follows

Ps://raw.githubusercontent.com/djstava/notebook/master/android/umeng/umeng_02.png "alt=" umneg_02 "style="- webkit-print-color-adjust:exact;max-width:100%; " />

Next to the Http://dev.umeng.com/analytics/android-doc/sdk-download download SDK, download the jar file from the Libs in the downloaded folder to the project Libs in the Android Right-click the jar file in studio and select Add as library to complete the import.


Configure Androidmanifest.xml

Add the appropriate permissions, as follows

&LT;USES-SDK android:minsdkversion= "4" ></uses-sdk>
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name= "Android.permission.INTERNET" ></uses-permission>
<uses-permission android:name= "Android.permission.READ_PHONE_STATE" ></uses-permission>

Then fill in the key and channel ID, a package can only add a channel, as follows

<meta-data android:value= "Here fill in the key value assigned by the league" Android:name= "Umeng_appkey"/>
<meta-data android:value= "Fill in the channel name here, such as Wandoujia or 360" android:name=, "Umeng_channel"

Integration Code

The Mobclickagent.onresume (context) is invoked in the Onresume method of each activity, and the Mobclickagent.onpause (context) is invoked in the OnPause method. If there is an inheritance relationship between the activity, do not repeat the Onresume and OnPause methods, or there will be duplicate statistics, affecting the statistical results. If you have a method called Process.kill or System.exit in the app that kills the process, be sure to call the Mobclickagent.onkillprocess (context) method before you can save the statistics.

At this point, the basic functionality has been integrated, or very simple. Some of the following advanced features can be added according to their own needs, the official document has been written in detail, here will no longer write, interested in the league's official website to see.



Friends of the league statistics how to calculate the new user Android

Android statistical Analysis SDK Usage Guide


1. Create app, download SDK


Login to your account, see the alliance's management backstage, click on "+ Add new Application" to enter the new application information fill out the page.

After the app is established, you can get the app's Appkey, along with the latest development guides and SDK files.

You can download the SDK here, including development documentation, demo programs, and Jar packs.

Description: Fill in the new application information, please fill in the real information as far as possible. You can save time by repeatedly building the app with the features of the Alliance's statistical analysis platform.
If you want to make statistics on different publishing channels for your app, and you don't need to create new apps, use distribution channel analysis to make it easier to compare data by distributing channel analysis.

2. To achieve basic use of basic statistics to achieve this page jump, model, resolution, location ... Statistics of 1. Import umeng-sdk*.jar (SDK) Download the latest version of the SDK Zip package, decompression will release the Umeng-sdk.jar to the local directory, the Eclipse user right key to your engineering root directory, select Properties-> Java Build Path-> Libraries, then click Add External JARs ... Select the path to the Analytics_android_sdk_*.jar, click OK, that is, import success.


2. Configure Androidmanifest.xml

<manifest......><application ......> ... <activity .../><meta-dataandroid:value= "YOUR_APP_KEY" Android £ º Name= "Umeng_appkey" ></meta-data><meta-dataandroid:value= "Channel ID" android:name= "UMENG_CHANNEL"/ ></application><uses-sdkandroid:minsdkversion= "4" ></uses-sdk><uses-permissionandroid: Name= "Android.permission.ACCESS_NETWORK_STATE" ></uses-permission><uses-permissionandroid:name= " Android.permission.INTERNET "></uses-permission><uses-permissionandroid:name=" Android.permission.READ_PHONE_STATE "></uses-permission><uses-permissionandroid:name=" Android.permission.READ_LOGS "></uses-permission></manifest>

Description


Meta-data use
Umeng_appkey is used to locate the uniqueness of the application.
Umeng_channel used to label application promotion channels, differentiate new users from the source to view statistics, you can use 20-bit English and numbers for the channel naming, replace the "CHANNEL ID" in value. See channel statistics for details.
Permission use
The Internet (must) allow applications to be networked to send data to our server side.
Read_phone_state (must) obtain the IMEI of the user's mobile phone to uniquely identify the user. (If your application will run on a tablet that cannot read the IMEI, we will use the MAC address as the user's unique identity, add permissions: Android.permission.ACCESS_WIFI_STATE)
Access_network_state detects network status, the Alliance SDK version 1.6 adds new permissions.
Read_logs if you want to obtain a report from the client crash, you need to add this permission. See "Using Error Reporting" specifically.
Write_external_storage If you use the Alliance Automatic Update reminder feature, you need to add this permission, in order to update the APK temporary presence in the SD card.


3. Add code


Add Reference: Import com.umeng.analytics.MobclickAgent

Registered activity: called Mobclickagent.onresume (context) in the Onresume method of each activity, called in the OnPause method
Mobclickagent.onpause (context)

Publicvoid Onresume () {super.onresume (); Mobclickagent.onresume (this);} Publicvoid OnPause () {super.onpause (); Mobclickagent.onpause (this);} api:public void Onresume (context)
Context the current activity's reference, please do not pass the global application context.
public void OnPause
Context the current activity's reference, please do not pass the global application context.
API Description:
void Onresume (Context context)
Context Current Activity Reference

void OnPause (Context context)
Context Current Activity Reference

Description
Method will automatically read the Appkey from the Androidmanifest.xml file.

Ensure that the Mobclickagent.onresume () and Mobclickagent.onpause () methods are invoked in all activity, and that these calls will not block the application's main thread or affect the performance of the application.

Note If there is an inheritance or control relationship between your activity, do not repeat the OnPause and Onresume methods in both parent and child activity, or you will cause duplicate statistics (eg. use Tabhost, tabactivity, When Activitygroup).

An application is considered to be the same session (startup) when it is continuously switched between multiple activity.

When the user is two times more than 30 seconds between use, will be considered to be two separate session (boot), such as the user back home, or into other programs, after a period of time before returning to the application.

4. Test


Verify that the required permissions have been added: INTERNET, Read_phone_state, (Read_logs, Write_external_storage)

Confirm that Appkey has been correctly written to Androidmanifest.xml

Confirm that the Onresume and OnPause methods are invoked in all activity

Confirm that the test phone (or emulator) has been successfully connected to the network

Start the application, and after a few minutes you should already be able to see the corresponding report.

3. Use error reporting the Friendship Union statistical analysis tool can also help you capture the exception exit (FC) that occurs when a user is using the application, and send an error report to the server the next time the application starts.
1. Auto-capture exception exit (FC)
Add permissions inside the Androidmanifest.xml Android.permission.READ_LOGS

Call Mobclickagent.onerror (context) in the OnCreate method of the program's main activity (application portal).

Publicvoid onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Mobclickagent.onerror (this); ...} api:public void OnError (context)
A reference to the current activity in the context
Description: The error report contains the application version, the operating system version and the device model, and the StackTrace when the program is abnormal, which will help you fix the bug in the application.
2. Manually send error reports If you have caught the exception in your program yourself, but you still want to send this exception message to your friend's server, you can call the following function.
Mobclickagent.reporterror (Context context,string error) Api:public void ReportError (context context, String error)
A reference to the current activity in the context

Error messages manually captured by the error developer
Note: The exception information that is sent manually and automatically captured is displayed in the Error Reporting panel.

4. Use custom events in addition to basic statistical analysis, we also support your customized event analysis, such as you can count the number of people who pass through different levels in the game, the number of clicks of the ad, or the number of times the video has been played, and so on. Using the custom event feature, the server does not process the corresponding custom event request until the appropriate custom event is added to the site application management background (set-> edit custom event).
1. Statistics of the number of events 1. In the part of the code that you want to track, call the following methods: Mobclickagent.onevent (Context context, String event_id); api:public void OnEvent (context context, String event_id)
A reference to the current activity in the context

EVENT_ID is the event ID for the current statistic, note that you want to register this event ID on the league web site first.
Example: The number of times a "forward" event occurs in a microblogging application is counted, and then a function called
Mobclickagent.onevent (This, "Forward") 2. To record the different attributes and values of the event, invoke the following methods: Mobclickagent.onevent (Context context, String event_id, map<string,string>; Map); Api:public voidonevent (context, String event_id, map map)
A reference to the current activity in the context

EVENT_ID is the event ID for the current statistic, note that you want to register this event ID on the league web site first.

Map is the property and collection of values for the current event (Key-value)
Example: Mobclickagent.onevent (Loginactivity.this, "Sinalogin");
Sina users log in to the sea to know notes

3. Consider the value of the event on a property, and you can call the following methods: Mobclickagent.onevent (Context, string event_id, string label); api:public void OnEvent (context, string event_id, String label)
A reference to the current activity in the context

EVENT_ID is the event ID for the current statistic, note that you want to register this event ID on the league web site first.

A property description of the label event
Example: Counting the number of levels of "death" events in the game, you can call it in the function of death
Mobclickagent.onevent (This, "Player_dead", "level"); 2. Event-length statistics have events that continue to occur and need to be recorded for a duration of two of solutions.
1. Call Oneventbegin and oneventend two functions respectively at the start and end of the event. Mobclickagent.oneventbegin (context context, String event_id); Mobclickagent.oneventend (context context, String event_id); Api:public Voidoneventbegin (context, String event_id)

public void Oneventend (context context, String event_id)
Context Current Activity Reference

EVENT_ID is the event ID for the current statistic, note that you want to register this event ID on the league web site first.
public void Oneventbegin (context, string event_id, String label)

public void Oneventend (context, string event_id, String label)
Context Current Activity Reference

EVENT_ID is the event ID for the current statistic, note that you want to register this event ID on the league web site first.

A property description of the label event
Example: Tracks the total time that a music event occurs, called at the beginning of music playback:
Mobclickagent.oneventbegin (This, "Music_play"), called at the end of music playback:
Mobclickagent.oneventend (This, "Music_play"); 2. An event with a long trace contains multiple properties that call the Onkveventbegin and onkveventend two function Mobclickagent.onkveventbegin at the start and end of the event (context, String event_id, map<string,string> Map, String ekvflag); Mobclickagent.onkveventend (context context, string event_id, string ekvflag); api:public void Onkveventbegin (context context, string event_id, map map, string ekvflag)
Context Current Activity Reference

EVENT_ID is the event ID for the current statistic, note that you want to register this event ID on the league web site first.

Map is the property and collection of values for the current event (Key-value)

Ekvflag Event Identifier
public void Onkveventend (context context, string event_id, String ekvflag)
Context Current Activity Reference

EVENT_ID is the event ID for the current statistic, and note that you want to register this event ID on the league web site first

Ekvflag event designator, Ekvflag and event_id to mark a unique event and not be counted; for the same event, the same onkveventend and event_id are to be passed in Onkveventbegin and flag
Example tracks how long each type of music plays and calls at the beginning of music playback
map<string,string> music = new hashmap<string,string> (); Music.put ("Type", "popular"); Music.put ("Artist", "Jjlin"); Music.put ("User_status", "registered"); Mobclickagent.onkveventbegin (This, "Music", Music, "M7"); called at the end of music playback:
Mobclickagent.onkveventend (This, "Music", Music, "M7"); 3. Calculate and upload the event's length yourself, and in the section of the code that you want to track, invoke the following methods: Mobclickagent.oneventduration (Context context, String event_id, long duration); O Rmobclickagent.oneventduration (context context, String event_id,string label, long Duration) Ormobclickagent.oneventduration (context, String event_id, map<string, String> Map, long Duration) api:public void Oneventduration (context context, String event_id, long Duration)

public void Oneventduration (context context, String event_id,string label, long Duration)
Context Current Activity Reference

EVENT_ID is the event ID for the current statistic, and note that you want to register this event ID on the league web site first

A property description of the label event

Duration event lasts for a long time, in milliseconds, you need to manually calculate and pass in the time length as the event's time-long argument
public void Oneventduration (context context, String event_id, Map map, long duration)
Context Current Activity Reference

EVENT_ID is the event ID for the current statistic, and note that you want to register this event ID on the league web site first

Map is the property and collection of values for the current event (Key-value)

Duration event lasts for a long time, in milliseconds, you need to manually calculate and pass in the time length as the event's time-long argument
Description
Duration is a new feature of the Alliance statistics, the use of the process may be some common mistakes, developers should try to avoid, here are some possible error cases.

The key of each event can not exceed 10, event ID, map key and value can not use special characters, and length can not exceed 255 characters (otherwise will intercept the first 255 characters), "ID", "ts", "Du" is a reserved field, not as an event Name of ID and key

5. Using distribution channel analysis sometimes needs to count the distribution channels of the application, such as how many users have downloaded your application from Legend Park, and how many users have downloaded to your application via Google Android Market. You only need to add meta-data to the Androidmanifest.xml and modify the Value property to the corresponding release channel name.
Configure Androidmanifest.xml Add the following code
<application ... ><activity .../><meta-dataandroid:value= "Channel ID" android:name= "UMENG_CHANNEL"/ ></application> Of course, this requires you to recompile the package when you publish the application in different channels.
Description
Do not change ' umeng_channel ', modify ' CHANNEL ID ' for your channel name, note cannot be a pure number (eg.value= "Androidmarket").

Each device only records the first statistics to the channel, if you find the channel statistics on the number of devices in the test does not increase, it is likely because you use the same device to modify the channel number, you change a device test can be.

6. Use the online Configuration feature to help you dynamically configure two types of parameters on your Web site:

The key value pairs of the custom Key-value type

Data Delivery Policy

Called in the OnCreate () method of the entry activity of the program
Publicvoid onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Mobclickagent.updateonlineconfig (this);} Api:public Voidupdateonlineconfig (context)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.