Qualifier and Type | Method Name and Description |
|---|---|
Promise<void> | setAnalyticsEnabled(flag: boolean) Sets whether to enable event tracking. |
Promise<void> | setUserId(userId:string) Sets a user ID. |
Promise<void> | setUserProfile(name:string,value:string) Sets user attributes. |
Promise<void> | setSessionDuration(sessionDuration: number) Sets the session timeout interval. |
Promise<void> | onEvent(eventId: string, params?: { [key: string]: any }) Records an event. |
Promise<void> | pageStart(screenName:string) Defines a page entry event. |
Promise<void> | pageEnd(screenName:string) Defines a page exit event. |
Promise<void> | setAppVersion(version: string) Sets the app version. |
Promise<{ [key: string]: string | number }> | getUserProfiles(preDefined: boolean) Obtains automatically collected or custom user attributes. |
Promise<void> | setRestrictionEnabled(flag: boolean) Sets whether to disable data analysis. |
Promise<boolean> | Checks whether data analysis is disabled. |
Promise<string> | getAAID() Obtains the Anonymous Application ID (AAID). |
Promise<void> | addDefaultEventParams(params?: { [key: string]: string | number | boolean | null }) Adds default event parameters. |
Promise<void> | setRoutePolicy(id: string | null ) Sets a data processing location. |
Promise<void> | setReportPolicies(policies: ReportPolicy) Sets a reporting policy. |
Promise<void> | onReport() Reports all events immediately. |
Method |
|---|
setAnalyticsEnabled(flag: boolean): Promise<void> Sets whether to enable event tracking. If the function is disabled, no data is recorded. NOTE:
|
Parameters
Name | Description |
|---|---|
flag | Indicates whether to enable event tracking. The default value is true.
|
Sample code:
The following code is used to disable event tracking.
... agconnect.instance().configInstance(aGConnectServicesConfig); window.analytics = agconnect.analytics(); window.analytics.setAnalyticsEnabled(false);
Method |
|---|
setUserId(userId:string): Promise<void> Sets a user ID. The SDK does not save the user ID. You are advised to set a user ID each time after the app is launched. |
Parameters
Name | Description |
|---|---|
userId | User ID, a string containing a maximum of 256 characters. The value cannot be empty. This anonymous user ID is associated with the user data by Analytics Kit. Only you can use this ID to trace a specific user, while Analytics Kit cannot. NOTE: When setting userId, comply with the HUAWEI Analytics Service Agreement and avoid using the original ID that can be used to identify a user. You are advised to use a random ID. |
Method |
|---|
setUserProfile(name:string,value:string): Promise<void> Sets 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 | Description |
|---|---|
name | User attribute name, a string containing a maximum of 256 characters. The value cannot be empty. It can consist of digits, letters, and underscores (_) and must start with a letter. |
value | User attribute value, a string containing a maximum of 256 characters. |
Method |
|---|
setSessionDuration(sessionDuration: number): Promise<void> Sets the session timeout interval. A new session will be generated when an app is running in the foreground but the interval between two adjacent events exceeds the specified timeout interval. |
Parameters
Name | Description |
|---|---|
sessionDuration | Session timeout interval, in milliseconds. The interval ranges from 5 seconds to 5 hours. If the specified value is beyond the value range, the boundary value is used. The default value is 1800000 (that is, 30 minutes). |
Method |
|---|
onEvent(eventId: string, params?: { [key: string]: any }): Promise<void> Records an event. |
Parameters
Name | Description |
|---|---|
eventId | Event ID, a string containing a maximum of 256 characters. The value cannot be empty or the ID of an automatically collected event. It can consist of digits, letters, and underscores (_), but cannot contain spaces or start with a digit. Example: event_description10 |
params | Information carried in an event. The number of key-value pairs cannot exceed 2048 and the length cannot exceed 204,800 characters. Each key in the key-value pairs can consist of digits, letters, and underscores (_), but cannot start with a digit. |
Method |
|---|
pageStart(screenName:string): Promise<void> Defines a page entry event. This method is usually used together with the pageEnd method. |
Parameters
Name | Description |
|---|---|
screenName | Name of the entry page. |
Method |
|---|
pageEnd(screenName:string): Promise<void> Defines a page exit event. This method is usually used together with the pageStart method. |
Parameters
Name | Description |
|---|---|
screenName | Name of the exit page. |
Method |
|---|
setAppVersion(version: string): Promise<void> Sets the app version. |
Parameters
Name | Description |
|---|---|
version | App version. The maximum length is 100 characters. |
Method |
|---|
getUserProfiles(preDefined: boolean):Promise<{ [key: string]: string | number }> Obtains automatically collected or custom user attributes. NOTE: This method cannot obtain the automatically collected attribute AAID. |
Parameters
Name | Description |
|---|---|
preDefined | Indicates whether to obtain automatically collected or custom user attributes.
|
Returns
Type | Description |
|---|---|
Promise<{ [key: string]: string | number }> | Automatically collected or custom user attributes. |
Method |
|---|
setRestrictionEnabled(flag: boolean): Promise<void> Sets whether to disable data analysis. The default value is false, which indicates that data analysis is enabled. |
Parameters
Name | Description |
|---|---|
flag | Indicates whether to disable data analysis. The default value is false.
|
Method |
|---|
isRestrictionEnabled(): Promise<boolean> Checks whether data analysis is disabled. |
Returns
Type | Description |
|---|---|
Promise<boolean> | true if data analysis is disabled; false otherwise. |
Method |
|---|
getAAID(): Promise<string> Obtains the AAID from AppGallery Connect. |
Returns
Type | Description |
|---|---|
Promise<string> | Promise that is used to obtain the AAID. |
Method |
|---|
addDefaultEventParams(params?: { [key: string]: string | number | boolean | null }): Promise<void> Adds default event parameters. These parameters will be added to all events except the automatically collected events. If the name of a default event parameter is the same as that of an event parameter, the event parameter will be used. |
Parameters
Name | Description |
|---|---|
params | Default event parameters. A maximum of 100 key-value pairs are supported. The key in each key-value pair can contain a maximum of 256 characters and can consist of only digits, letters, and underscores (_), but cannot start with a digit. The value in each key-value pair can contain a maximum of 256 characters, and can only be of the string, number, or Boolean type, or be null. NOTE:
|
Method |
|---|
setRoutePolicy (id: string | null ): Promise<void> Sets a data processing location. NOTE:
|
Parameters
Name | Description |
|---|---|
id | Data processing location. The options are CN (China), DE (Germany), SG (Singapore), and RU (Russia). NOTE:
|