Analytics are fairly simple as the main logging happens in the background. HMS has some extra functionality where the page exit can be set as well, this might be needed to get improved analytics accuracy.
We recommend to enabled "Advanced Analytics Service" in AppGallery Connect (under "HUAWEI Analytics"). Please make sure to re-download agconnect-services.json
after enabling it and add additional Gradle dependencies:
Project
gradle:
buildscript {
dependencies {
classpath 'com.huawei.hms.plugin:analytics:5.0.1.300'
}
}
App
gradle:
apply plugin: 'com.huawei.hms.plugin.analytics'
dependencies {
implementation 'com.huawei.hms:hianalytics:5.0.1.300'
}
Getting the analytics instance:
val analytics: Analytics = AnalyticsFactory.getAnalytics(this)
Sending custom events:
val bundle: Bundle = Bundle()
bundle.putString("custom_key", "custom_value")
analytics.logEvent("Demo_Analytics_Btn", bundle)
Setting current screen:
analytics.setCurrentScreen(this, "Demo_Analytics_Screen", null)
Setting a user property:
analytics.setUserProperty("loves_tea", "definitely")