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:
A computer (desktop or laptop)
To integrate Analytics Kit, you must complete the following preparations:
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.
npm init
npm install --save @hw-hmscore/analytics-sdk-miniprogram
View the demo effect.
Your app is so far loaded with the required functions. Next, you will use Analytics Kit to report the events that interest you.
As npm is used as the package management tool, you can run the npm install command to install required dependencies. In this codelab, the SDK dependencies have been added to the package.json file, and required SDKs have been installed after the npm install command is executed in the previous step. You can check the dependencies or manually run the following command to install the dependencies:
npm install --save @hw-hmscore/analytics-sdk-miniprogram
// TODO: Import necessary modules.
import agconnect from '@agconnect/api';
import '@agconnect/instance';
import '@hw-hmscore/analytics-sdk-miniprogram';
// TODO: Replace the following code with the configuration of your app.
const agConnectConfig = {
// ...
};
// Initialize the configuration.
agconnect.instance().configInstance(agConnectConfig);
// Initialize the Analytics Kit instance.
let analytics = agconnect.analytics();
this.globalData.analytics = agconnect.analytics();
this.globalData.agconnect = agconnect;
const app = getApp();
reportAnswer(answer) {
// TODO: Report a custom event.
let answerTime = this.formatDate();
let reportMessage = {
question: this.data.questions[this.data.currentNumber],
answer: answer,
answerTime: answerTime
}
app.globalData.analytics.onEvent("Answer", reportMessage);
}
postScore() {
// TODO: Report a score through the SUBMITSCORE event.
let scoreMessage = {}
scoreMessage[app.globalData.agconnect.analytics.ParamName.SCORE] = this.data.score;
app.globalData.analytics.onEvent(app.globalData.agconnect.analytics.EventName.SUBMITSCORE, scoreMessage);
}
Add the following code to save user attributes:
save() {
this.data.sport && app.globalData.analytics.setUserProfile('favor_sport', this.data.sport);
wx.navigateBack();
}
Click Preview to start the app and trigger event reporting as prompted.
Perform initialization at the beginning of the app.js file. 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:
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:
For more information, please click the following link:
Related documents
To download the sample code, please click the button below: