Accessing HUAWEI Analytics Kit

1,035 posts
Thanks Meter: 1,119
By XDARoni, XDA Community Manager on 30th June 2020, 05:27 PM
Post Reply Email Thread
HUAWEI Analytics Kit is based on the event analytics data model.

The analytics data model uses the Event-Param-User model to record data, describes events using parameters, and describes the characteristics of users.

HUAWEI Analytics Kit collects the AAID that is allocated by the HMS Instance ID to each app instance installed on the device. The AAID is used for connecting various HMS Core services, such as HUAWEI Push Kit, HUAWEI Analytics Kit, and Remote Configuration.

The AAID will be reset in the following scenarios:
  • The user uninstalls or reinstalls the app.
  • The user restores the device to its factory settings.
  • The user clears the app data.
  • The app calls the clearCachedData API.

1. Initialize the HMS Core Analytics SDK by calling the getInstance API.
HiAnalyticsInstance instance = HiAnalytics.getInstance(context);
2. Record defined events using the onEvent API. For definitions of the events, please refer to Event Description.
3. Call APIs of HUAWEI Analytics Kit to implement the corresponding functions. For details, please refer to API Reference. For example, call the setUserProfile API to set user attributes.

Sample Code
1. After the agconnect-services.json file is imported successfully, initialize HUAWEI Analytics Kit in the onCreate method of the first activity to obtain a HiAnalyticsInstance instance. If the agconnect-services.json file is incorrect, data cannot be collected at specified trigger points.
protected void onCreate(Bundle savedInstanceState) {
    //Enable SDK log recording.
    HiAnalyticsInstance instance = HiAnalytics.getInstance(this);
    // Or use the context for initialization.
    // Context context = this.getApplicationContext();
    // HiAnalyticsInstance instance = HiAnalytics.getInstance(context);
    // instance.setUserProfile("userKey","value"); 
2. Insert trigger points in proper positions of the code.
//Customize trigger points and add trigger points in the proper position of the code.
Bundle bundle = new Bundle();
instance.onEvent("begin_examination", bundle);
//Add trigger points for predefined events.
Bundle bundle_pre = new Bundle();
bundle_pre.putString(PRODUCTID, "item_ID");
bundle_pre.putString(PRODUCTNAME, "name");
bundle_pre.putString(CATEGORY, "category");
bundle_pre.putLong(QUANTITY, 100L);
bundle_pre.putDouble(PRICE, 10.01);
bundle_pre.putDouble(REVENUE, 10);
bundle_pre.putString(CURRNAME, "currency");
bundle_pre.putString(PLACEID, "location_ID");
instance.onEvent(ADDPRODUCT2WISHLIST, bundle_pre);
Using the Debug Mode
During the development, you can enable the debug mode to view the event records in real time, observe the results, and adjust the event tracing scheme.

Enabling/Disabling the Debug Mode
Run the following command on an Android device to enable the debug mode:
adb shell setprop package_name
After the debug mode is enabled, all events will be reported in real time.

Run the following command to disable the debug mode:
adb shell setprop .none.
You can go to HUAWEI Analytics > Management > App Debugging to view the reported data, as shown in the following figure.

For details about how to view the analysis data, please refer to App Debugging.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes