目录

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.

Term

Meaning

Description

Event

Event

An event describes a specific task completed by a user at a location using a method at a time, including key elements such as who, when, where, how, and what.

Param

Parameter

Associated parameters reported in events, for example, the product name and product price parameters in the event of a product being added to the shopping cart. These parameters can be used for subsequent in-depth analytics.

UserProfiles

User attribute

List of user attributes. Common user attributes include the ODID, device model, app version, and custom user attributes such as food preferences.

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 Huawei services, such as HUAWEI PUSH Kit, HUAWEI Analytics Kit, and remote configurations.

The AAID will be reset in the following scenarios:

Procedure

1. Initialize the HMS Core Analytics SDK by calling the getInstance API.

  1. HiAnalyticsInstance instance = HiAnalytics.getInstance(context);
Note:
In this example, the type of context is Activity. Context initialization has been supported since 2.3.0.304.

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 an instance of HUAWEI Analytics Kit. If the agconnect-services.json file is incorrect, data cannot be collected at specified tracing points.

  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3.    super.onCreate(savedInstanceState);
  4.    setContentView(R.layout.activity_main);
  5.    //Enable SDK log recording.
  6.    HiAnalyticsTools.enableLog();
  7.    HiAnalyticsInstance instance = HiAnalytics.getInstance(this);
  8.    //Or, use context initialization.
  9.    // Context context = this.getApplicationContext();
  10.    // HiAnalyticsInstance instance = HiAnalytics.getInstance(context);
  11.    // instance.setUserProfile("userKey","value")
  12. }

2. Insert tracing points in proper position of the code.

  1. //Customize tracing points and add tracing points in the proper position of the code.
  2. Bundle bundle = new Bundle();
  3. bundle.putString("exam_difficulty","high");
  4. bundle.putString("exam_level","1-1");
  5. bundle.putString("exam_time","20190520-08");
  6. instance.onEvent("begin_examination", bundle);
  7. //Add tracing points for predefined events.
  8. Bundle bundle_pre = new Bundle();
  9. bundle_pre.putString(PRODUCTID, "item_ID");
  10. bundle_pre.putString(PRODUCTNAME, "name");
  11. bundle_pre.putString(CATEGORY, "category");
  12. bundle_pre.putLong(QUANTITY, 100L);
  13. bundle_pre.putDouble(PRICE, 10.01);
  14. bundle_pre.putDouble(REVENUE, 10);
  15. bundle_pre.putString(CURRNAME, "currency");
  16. bundle_pre.putString(PLACEID, "location_ID");
  17. 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

1. Run the following command to enable the debug mode on an Android device:

  1. adb shell setprop debug.huawei.hms.analytics.app package_name

After the debug mode is enabled, all events will be reported in real time.

Note:
Replace the package_name field in the command with your app package name.

2. Run the following command to disable the debug mode:

  1. adb shell setprop debug.huawei.hms.analytics.app .none.

Successfully reported data is displayed on Huawei Developers in real time, as shown in the figure below.

For details about how to view analysis data on Huawei Developers, please refer to App Debugging.