1. The RegHmsSvcEvent() and UnRegHmsSvcEvent() APIs must be used together.
2. You are advised to call the UnRegHmsSvcEvent() API in the OnDestroy() method of MainActivity or Application
This is a single-instance Analytics class that provides public methods for reporting user behavior data.
| Name | Description |
|---|---|
SetAnalyticsEnabled | This API is called to specify whether to enable data collection based on predefined measurement points. |
SetUserId | This API is called to set user IDs. |
SetUserProfile | This API is called to set user attributes. |
SetPushToken | This API is called to set the push token, which can be obtained from HUAWEI Push Kit. |
SetMinActivitySessions | This API is called to set the minimum interval between two sessions. |
SetSessionDuration | This API is called to set the session timeout interval. |
SetCurrentActivity | This API is called to set the current screen name, which is used to identify the currently displayed screen. |
OnEvent | This API is called to record events. |
ClearCachedData | This API is called to delete all collected data cached locally, including cached data that failed to be sent. |
AAID | This API is called to obtain the app instance ID from AppGallery Connect. |
RegHmsSvcEvent | This API is called to register services of HUAWEI Analytics Kit to report service events related to HUAWEI IDs and in-app purchases. |
UnRegHmsSvcEvent | This API is called to deregister services of HUAWEI Analytics Kit. |
GetUserProfiles | This API is called to obtain user attributes. |
This API is called to specify whether to enable data collection based on predefined measurement points. If the data collection is disabled, no data is recorded.
Parameters | |
enabled | Indicates whether to enable automatic event collection. The options are as follows: True: Automatic event collection is enabled. False: Automatic event collection is disabled.The default value is True. |
This API is called to specify whether to enable data collection based on predefined measurement points. If the data collection is disabled, no data is recorded.
Parameters | |
enabled | Indicates whether to enable automatic event collection. The options are as follows: True: Automatic event collection is enabled. False: Automatic event collection is disabled.The default value is True. |
This API is called to set user IDs.
When the API is called, a new session is generated if the old value of userId is not empty and is different from the new value. If you do not want to use userId to identify a user (for example, when a user signs out), you must set userId to null.
id: ID of a user. Huawei Analytics uses this ID to associate user data.The use of userId must comply with related privacy regulations. You need to declare the use of such information in the privacy statement of your app.
Parameters | |
id | Indicates the user ID.This parameter cannot be empty and its value can contain a maximum of 256 characters. |
This API is called to set user attributes.The values of user attributes remain unchanged throughout the app lifecycle and during each session.A maximum of 25 user attributes are supported. If the name of an attribute set later is the same as that of an existing attribute, the value of the existing attribute is updated.
Parameters | |
name | Indicates the ID of a user attribute.The value cannot be empty and can contain a maximum of 256 characters, including digits, letters, and underscores (_). It cannot start with a digit or underscore. |
value | Indicates the attribute value, which is a non-empty string containing up to 256 characters. |
This API is called to set the push token. After obtaining a push token through HUAWEI Push Kit, use this method to save the push token so that you can use the audience defined by HUAWEI Analytics to create HCM notification tasks.
Parameters | |
token | Push token, which is a non-empty string containing up to 256 characters. |
This API is called to set the minimum interval for starting a new session. A new session is generated when an app is switched back to the foreground after it runs in the background for the specified minimum interval. The default value is 30 seconds.
Parameters | |
milliseconds | Indicates the minimum interval between two sessions. Unit: ms |
This API is called to set the session timeout interval. A new session is generated when an app keeps running in the foreground but the interval between two adjacent events exceeds the specified timeout interval. The default value is 30 minutes.
Parameters | |
milliseconds | Indicates the session timeout interval. Unit: ms |
This API is called to set the current screen name, which is used to identify the currently displayed screen.
Note:
HUAWEI Analytics Kit automatically collects the $CurActivityName parameter in the $EnterScreen and $ExitScreen events, and uses the parameter value as the name of the current screen. To overwrite the automatically collected $EnterScreen and $ExitScreen events, you can call this API in OnResume of Activity and specify the screen name (activityName, which is mandatory) and class name (activityClassOverride, which is optional. If this parameter is null or left empty, HUAWEI Analytics Kit will obtain the class name based on the passed activity.)
You can also call this API to record non-activity screen events (such as fragment and custom view) and specify the screen name (activityName, which is mandatory).
Parameters | |
activity | Indicates the current activity. |
activityName | Indicates the name of the current activity screen, which is mandatory.This parameter cannot be empty and its value can contain a maximum of 256 characters. |
activityClassOverride | Indicates the screen class name, which is optional. If this parameter is set to null or left empty, the class name of the current activity is used.The value can contain a maximum of 256 characters. |
This API is called to record events.
Parameters | |
name | Indicates the ID of a customized event.The value cannot be empty and can contain a maximum of 256 characters, including digits, letters, and underscores (_). It cannot start with a digit or underscore. The value of this parameter cannot be an ID of an automatically collected event. |
params | Indicates the information carried by the event. The number of built-in key-value pairs in the bundle cannot exceed 2048 and the size cannot exceed 200 KB.The key value in the Bundle class consists of digits, letters, and underscores (_) and cannot start with a digit. |
This API is called to delete all collected data cached locally, including cached data that failed to be sent.
This API is called to obtain the app instance ID from AppGallery Connect.
Return | |
Task | Task for getting an app instance ID. |
Registers services of HUAWEI Analytics Kit to support automatic collection of events such as HUAWEI ID sign-in and sign-out, in-app purchases, and ads.
This API is called to deregister services of HUAWEI Analytics Kit.
1. The RegHmsSvcEvent() and UnRegHmsSvcEvent() APIs must be used together.
2. You are advised to call the UnRegHmsSvcEvent() API in the OnDestroy() method of MainActivity or Application
This API is called to obtain predefined and custom user attributes in the A/B test.
Parameters | |
preDefined | Indicates whether to obtain predefined user attributes. True: obtains predefined user attributes False: obtains developer-defined user attributes |
Return | |
IDictionary<string, string> | Predefined or custom user attributes. |