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:
Efficiently integrate Analytics Kit.
Correctly use APIs of Analytics Kit.
Hardware Requirements
A computer (desktop or laptop)
An Android phone
Software Requirements
Cocos Creator
Visual Studio Code
Huawei Quick App IDE v3.1.1 or later
Android SDK
NDK
To integrate Analytics Kit, you must complete the following preparations:
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.
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.
Connect your phone to your computer and enable the debug mode on your phone.
Go to Project > Build....
To release a runtime quick game, perform the following operations: a) In the Build... dialog box displayed, set Platform to Huawei Quick Game and click Build. After the build is complete, click Play. b) In the QuickGame Devtools dialog box displayed, click ▶ to run the project.
To release an HTML5 quick game, perform the following operations: a) In the Build... dialog box displayed, set Platform to Web Mobile and click Build. After the build is complete, click Play. b) After a successful startup, use Quick App IDE to open and run the HTML5 quick game project. c) Refer to the precautions for using SSL certificates to deal with the SSL error.
After a successful startup, you will see a demo with the question answering function on the mobile phone.
Your app is so far loaded with the required functions. Next, you will use Analytics Kit to report the events that interest you.
Installing SDK Dependencies
Place the hw-hmscore-analytics-sdk-quickgame-xx.xx.xx.esm.js and agconnect-quickgame-xx.xx.xx-min.js files in the assets/Lib directory, and import the files as plugins in Cocos Creator.
To download hw-hmscore-analytics-sdk-quickgame-xx.xx.xx.esm.js, click Quick Game SDK Download.
To download agconnect-quickgame-xx.xx.xx-min.js, click the link in the following table.
Sign in to AppGallery Connect, click My projects, and find the app that needs to integrate the SDK. Then go to the Project settings page, and download the agconnect-services.json file.
Assign the file content to the aGConnectServicesConfig variable in the Analytics.js file. If the Analytics.js file does not exist, create one or copy it from the demo.
// TODO: Initialize Analytics Kit.
var aGConnectServicesConfig = {};
Bind the Analytics.js file to the root objects (usually the Canvas objects) of all scene files.
Add the following code to the Question.js file to implement the reportAnswer method (for reporting a custom event as an example):
In the QuickGame Devtools dialog box displayed, click ▶ to run the project.
On the initial screen, if you tap True or False to answer a question, the custom Answer event will be reported. After finishing all questions, if you tap POST SCORE to post your score, the predefined $SubmitScore event will be reported; if you tap SETTINGS, the user attribute setting screen will be displayed.
On the SETTING screen, enter your favorite sport and tap CONFIRM.
Bind the Analytics.js file to the root objects (usually the Canvas objects) of all scene files.
Why can't I view the analysis result of the data reported during the test?
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 the day after the corresponding data is processed.
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: