How to use automatically collected, predefined and custom events with HMS Analytics Kit ?

Ismail Oguzhan Ay
Huawei Developers
Published in
6 min readOct 27, 2020

Hello everyone, today we will talk about Analytics Kit, which is valuable in terms of analysis and reporting that we use frequently in our applications. With the Huawei Analytics Kit, we will examine user behavior using custom events and predefined events from our demo application.

Functions

Intelligent dashboards

Monitors app performance in preset and custom dashboards for faster operations.

Diverse analytics models

Analyzes events, audiences, funnels, attribution, behavior, retention, real-time data, and app versions for data-driven app lifecycle management.

App debugging

Allows final debugging on data reporting, preventing tracing point omission and event attribute setting errors.

Before starting the demo application review, there are important details about the Huawei Analytics Kit below.

1. What is AAID ?

Anonymous device ID opened to third-party apps. Each app is allocated with a unique AAID on the same device so that statistics can be collected and analyzed for different apps (for example, statistics on the number of active users).

2. Which the following scenarios AAID will be reset ?

  • The user reinstalls the app.
  • The user restores the device to its factory settings.
  • The user clears the app data.
  • The app calls the clearCachedData() API.

3. What Data Does the SDK Collect?

The SDK collects the following types of data:

  • Common event attributes: ROM version number, device model, app name, package name, channel number, app version number, operating system version, system language, manufacturer, screen width, screen height, operation time, and device type
  • Custom events: custom events to be collected
  • Automatically collected events

4. What Permissions Are Required for Using the SDK?

Analytics Kit has integrated the required permissions. Therefore, you do not need to apply for these permissions.

  • android.permission.INTERNET: Network access permission
  • android.permission.ACCESS_NETWORK_STATE: Network status check permission
  • com.huawei.Appmarket.service.commondata.permission.GET_COMMON_DATA: AppGallery channel ID query permission

5. About the service restrictions

  • Device restrictions: The following automatically collected events of Analytics Kit depend on HMS Core (APK), and therefore are not supported on third-party devices where HMS Core (APK) is not installed (including but not limited to OPPO, VIVO, Xiaomi, Samsung, and OnePlus): INSTALLAPP (app installation), UNINSTALLAPP (app uninstallation), CLEARNOTIFICATION (data deletion), INAPPPURCHASE (in-app purchase), RequestAd (ad request), DisplayAd (ad display), ClickAd (ad tapping), ObtainAdAward (ad award claiming), SIGNIN (sign-in), and SIGNOUT (sign-out).
  • Event quantity restrictions: A maximum of 500 events are supported.
  • Event parameter restrictions: You can define a maximum of 25 parameters for each event, and a maximum of 100 event parameters for each project.
  • Supported locations: The service is available only in the locations listed in Supported Locations.

Development Process

We need to follow some steps for the integration of Huawei Analytics Kit.

Huawei Analytics Kit Development Process Flow
  1. We need to register as a developer account in AppGallery Connect.
  2. We create an application and enable analytics kit from AppGallery Connect.

3. After the configuration in AppGallery Connect, let’s integrate the Huawei Analytics Kit into our demo application.

a. We need to get agconnect-services.json file for configurations from AppGallery Connect. Then, we add it into our application project level under the app folder.

b. After that, we need to add dependencies into gradle files.

Now, we need to sync our gradle files.

Let’s start the coding !

We have an activity(MainActivity.kt) for handling the actions about the custom and predefined events. So, it has a layout which is activity_main.xml. There is a separation in layout for dividing custom and predefined events. Let’s check them.

1. Adding the predefined events

In AppGallery Connect, from left side menu, we can open the HUAWEI Analytics, then Management -> Events. We can add the predefined parameters as like at pictures. We used the addProduct2Cart predefined event and add its registered parameters.

2. Adding the custom events

We can create the custom evets for our special events and their parameters. So, we create a custom parameter which name is CustomEventFeedback. We uses it for getting feedback parameter from our users. We add a parameter which name is CustomEventFeedbackParamResult, it uses for getting feedback parameter option as like as “Yes” or “No” actions.

Custom Event Constants

In predefined event demo, we have a product which is a phone and we want to catch the case of add to cart for our users. When the user clicks to add to cart, the button click sends the predefined events parameters to Huawei Analytics Kit. We use HAEventType.ADDPRODUCT2CART predefined event in that sample. As a sample that case, we can analyze and report our users actions. More information about the predefined events list.

In custom event demo, we have a question about the feedback from our users. When the user clicks yes or no button, the button click sends the custom event parameters to Huawei Analytics Kit. As a sample that case, we can create our custom events and parameters for our analysis and reports.

Event Data From Huawei Analytics

Huawei Analytics Kit supports real-time overview analysis. In AppGallery Connect, from left side menu, we can see the details about the app analysis in last 30 minutes.

At the chart view, we can see event analysis, this list shows us automatically collected events, predefined events and custom events. In that case, there are 5 parameters about the showing automatically collected events.

We can see AddProduct2Cart predefined events here with its parameters from the application.

Also, we can see the custom events here. When the user select an option and send it from application, we can see the customEventFeedback and its result parameters.

--

--