目录

Function Summary

InterfaceDescription
clearCachedDataThis API is called to delete all collected data cached locally, including cached data that failed to be sent.
enableLogEnables the console log function of the SDK. The default level is DEBUG.
enableLogWithLevelEnables the console log function of the SDK. The log level is passed.
getAAIDThis API is called to obtain the app instance ID from AppGallery Connect.
onEventThis API is called to record events.
setCurrentScreenThis API is called to set the current screen name, which is used to identify the currently displayed screen.
setMinActivitySessionsThis API is called to set the minimum interval between two sessions.
setSessionDurationThis API is called to set the session timeout interval.
setUserIdThis API is called to set user IDs.
setUserProfileThis API is called to set user attributes.

Public Functions

Method

void clearCachedData()

This API is called to delete all collected data cached locally, including cached data that failed to be sent.
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

Method

void enableLog()

Enables the console log function of the SDK. The default level is DEBUG.
ParameterDescription
Method

void enableLogWithLevel(String level)

Enables the console log function of the SDK. The log level is passed.

Parameters

ParameterDescription
levelLog level. The value can be debug, info, warn, or error. The value is case sensitive.
Method

promise getAAID()

This API is called to obtain the app instance ID from AppGallery Connect.

Return

ParameterDescription
promise

If the operation is successful, an ID of the string type is returned. If the operation fails, an error message of the string type is returned. The response is obtained from the resolve function.

Method

void onEvent(String name, object params)

This API is called to record events.

Parameters

ParameterDescription
nameIndicates 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 anautomatically collected event.
paramsIndicates the information carried by the event.The number of built-in key-value pairs in the object cannot exceed 2048 and the size cannot exceed 200 KB. The key value in the object cannot contain spaces or invisible characters.
Method

void setCurrentScreen(String activityName, String activityClassOverride)

This API is called to set the current screen name, which is used to identify the currently displayed screen.

Parameters

ParameterDescription
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.

screenClassOverrideIndicates 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.
Method

void setMinActivitySessions(Number milliseconds)

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

ParameterDescription
milliseconds

Indicates the minimum interval between two sessions.The value is an integer.

Unit: ms

Method

voidsetSessionDuration(long milliseconds)

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

TypeDescription
milliseconds

Indicates the session timeout interval.The value is an integer.

Unit: ms

void setUserId(String id)

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

ParameterDescription
idIndicates the user ID.This parameter cannot be empty and its value can contain a maximum of 256 characters.

void setUserProfile(String name, String value)

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.

valueIndicates the attribute value,which is a non-empty string containing up to 256characters.
Method
Method