Analytics Kit predefines rich analysis models to help you easily understand user behavior and gain in-depth insights into users, products, and content. As such, you can carry out data-driven operations and make informed decisions about app marketing and product optimization.
Analytics Kit implements the following functions using data collected from apps:
In this codelab, you will create a demo app based on the provided demo project. After creating a demo app, you will be able to:
In this codelab, you will learn how to:
To integrate Analytics Kit, you must complete the following preparations:


dependencies {
classpath 'com.huawei.agconnect:agcp-harmony:1.3.0.300'
}
dependencies {
implementation 'com.huawei.hms:hianalytics-harmony:6.10.0.300'
}
c) Add the AppGallery Connect plugin configuration.apply plugin: 'com.huawei.agconnect'
npm install @hw-hmscore/analytics-sdk-harmony
Before building the app, configure the obfuscation configuration file to prevent the Analytics SDK from being obfuscated.
Open the obfuscation configuration file proguard-rules.pro in the app-level directory, and add configurations to exclude the Analytics SDK and SDKs it depends on from being obfuscated.
-ignorewarnings
-keep class com.huawei.agconnect.**{*;}
-keep class com.huawei.hms.analytics.**{*;}
-keep class com.huawei.hms.push.**{*;}
In this section, you will try to build a demo with the question answering function to learn how to use the main APIs of Analytics Kit. We have prepared the code for you, meaning you only need to follow the instructions in each step below to learn how to use Analytics Kit to report the events you are interested in, such as answering questions, calculating scores, and setting user attributes.
"module": {
"js": [
{
"name": "default",
"window": {
"designWidth": 750,
"autoDesignWidth": false
},
"pages": [
"pages/index/index",
"pages/setting/setting",
"pages/result/result"
]
}
],
}
"module": {
"abilities": [
{ ......
},
{
"permissions": [
"com.huawei.agconnect.core.DataAbilityShellProvider.PROVIDER"
],
"name": "com.huawei.agconnect.core.provider.AGConnectInitializeAbility",
"type": "data",
"uri": "dataability:// com.example.myapplication.AGConnectInitializeAbility"
},
{
"name": "com.huawei.hms.analytics.AnalyticsServiceAbility",
"icon": "$media:icon",
"visible":false,
"type": "service"
},
]
}
Your app is so far loaded with the required functions. Next, you will use Analytics Kit to report the events that interest you.
import analytics from '@hw-hmscore/analytics-sdk-harmony';
globalData: {
analytics: null
},
// TODO: Replace the following code with the configuration of your app.
onCreate() {
let bundleName = 'com.huawei.harmonyos.demo';
analytics.getInstance(bundleName);
},
For details about APIs, please refer to the Analytics Kit API Reference.
Start the app in the emulator and trigger event reporting as instructed.

hdc shell setprop debug.huawei.hms.analytics.hap <package_name>
After the debug mode is enabled, all triggered events are reported to the App debugging page in real time.
To disable the debug mode, run the following command:
hdc shell setprop debug.huawei.hms.analytics.hap .none.
Initialize the Analytics SDK in the main thread by using the onCreate method of app.js. Otherwise, the processing of automatically collected lifecycle events may be affected.
Analytics Kit identifies users through an Anonymous Application ID (AAID).
The AAID will be reset in the following scenarios:
Analytics Kit requires the ohos.permission.INTERNET permission, which has been preset in Analytics Kit. You do not need to apply for this permission.
Well done. You have successfully completed this codelab and learned how to:
For more information, please click the following link:
Related documents
To download the sample code, please click the button below: