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:
Collects and reports custom events through coding.
Sets up to 25 user attributes.
Automatically collects events, calculates sessions, and predefines event IDs and parameters.
What You Will Create
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:
Report events using the Analytics SDK.
View event analysis reports on the cloud platform of Analytics Kit.
What You Will Learn
In this codelab, you will learn how to:
Use Android Studio to efficiently integrate capabilities of Analytics Kit.
Correctly use APIs of Analytics Kit.
Hardware Requirements
A computer (desktop or laptop)
A Huawei phone used for running and debugging the developed app
Find your project and select the app that needs to integrate the Analytics SDK.
Select any menu under HUAWEI Analytics and click Enable Analytics service. (You must have the app management permission to perform this operation.)
On the Project access settings page displayed, set the data processing location and complete other settings. Then click Finish.
Download the configuration file.
In Android Studio, switch to the Project view and copy the agconnect-services.json file to your app-level directory.
Adding SDK Dependencies
Add the Maven repository address and AppGallery Connect dependency to the build.gradle file of your project.
a) Open the project-level build.gradle file.
b) Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
c) Add the AppGallery Connect plugin configuration. Select a method as required.
Method 1: Add the following configuration under the declaration in the file header:
apply plugin: 'com.huawei.agconnect'
Method 2: Add the plugin configuration in the plugins block.
plugins {
id 'com.android.application'
// Add the following configuration:
id 'com.huawei.agconnect'
}
Click Sync Now or Sync Project with Gradle Files to build a project.
Configuring Obfuscation Scripts
If you are using AndResGuard, add its trustlist to the obfuscation configuration file.
In this section, you will try to build a demo to learn how to use the main APIs of Analytics Kit, for example, the API for recording custom events or setting user attributes.
Initialize Analytics Kit in the main thread by using the onCreate() method of the first app activity. Otherwise, the processing of automatically collected lifecycle events may be affected.
How does Analytics Kit identify users?
Analytics Kit identifies users through an Anonymous Application ID (AAID).
When will the AAID be reset? How does Analytics Kit collect user statistics after AAID reset?
The AAID will be reset in the following scenarios:
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. A user is counted as a new one after their AAID is reset.
What permissions are required for using Analytics Kit?
Analytics Kit requires the following permissions, which have been preset in Analytics Kit. You do not need to apply for these permissions.
Why can't I view the analysis result of the data reported during the test?
When app debugging is disabled, you can only view some analysis results on the Real-time overview page. Analysis results on other pages such as Event analysis and Launch analysis are available only after the corresponding data is processed on the next day.
When app debugging is enabled, the reported test data will not be analyzed and can only be viewed on the App debugging page.
What should I do if a gradle-wrapper.properties file error is reported?
This error may occur if the Gradle version configured in the sample code of Analytics Kit is later than the one you currently use. To correct the error, you are advised to change the Gradle version to an earlier version, for example, gradle-4.10.2-all.
Well done. You have successfully completed this codelab and learned how to:
Integrate Analytics Kit.
Call APIs of Analytics Kit.
For more information, please click the following link:
Related documents To download the sample code, please click the button below: