Class Info |
|---|
Provides public methods to report user behavior data. |
Qualifier and Type | Method Name and Description |
|---|---|
void | Initializes Analytics Kit. |
void | configWithRoutePolicy:(nonnull NSString *)routePolicy Initializes Analytics Kit. To call this method, you must set a data processing location. |
void | setReportPolicies:(nullable NSArray<HAReportPolicy *> *)policies Sets data reporting policies. |
void | onEvent:(nonnull NSString *)eventId setParams:(nonnull NSDictionary<NSString *, id> *)params Records an event. |
void | setUserProfile:(nonnull NSString *)name setValue:(nullable NSString *)value Sets user attributes. |
nullable NSDictionary<NSString *, id> * | userProfiles:(BOOL)preDefined Obtains automatically collected or custom user attributes. |
void | setAnalyticsEnabled:(BOOL)enabled Sets whether to enable event tracking. |
nonnull NSString * | Obtains the Anonymous Application ID (AAID). |
void | setUserId:(nullable NSString *)userId Sets a user ID. |
void | setSessionDuration:(NSTimeInterval)milliseconds Sets the session timeout interval. |
void | Clears all the collected data in the local cache. |
void | setRestrictionEnabled:(BOOL)enabled Sets whether to disable data analysis. |
BOOL | Checks whether data analysis is disabled. |
void | setCollectAdsIdEnabled:(BOOL)isEnabled Sets whether to collect IDFAs. |
void | addDefaultEventParams:(nullable NSDictionary<NSString *, id> *)params Adds default event parameters. |
void | setMinActivitySession:(NSTimeInterval)milliseconds Sets the minimum interval for refreshing a session when your app is running in the background. |
Method |
|---|
+ (void)config Initializes Analytics Kit. Analytics Kit will be initialized in the main thread based on your configuration. NOTE:
|
Method |
|---|
+ (void)configWithRoutePolicy:(nonnull NSString *)routePolicy Initializes Analytics Kit. Analytics Kit will be initialized in the main thread based on your configuration. NOTE:
|
Parameters
Name | Description |
|---|---|
routePolicy | Data processing location. The options are CN (China), DE (Germany), SG (Singapore), and RU (Russia). NOTE: The data processing location you set must have the data storage permission. Otherwise, data cannot be reported to it. |
Method |
|---|
+ (void)setReportPolicies:(nullable NSArray<HAReportPolicy *> *)policies Sets data reporting policies. |
Parameters
Name | Description |
|---|---|
policies | Policy for data reporting. Four policies are supported. One or more policies can be specified.
|
Method |
|---|
+ (void)onEvent:(nonnull NSString *)eventId setParams:(nonnull NSDictionary<NSString *, id> *)params 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 built-in key-value pairs in the dictionary cannot exceed 2048 and the dictionary cannot exceed 204,800 characters. Each key in the key-value pairs can consist of digits, letters, underscores (_), and the dollar sign ($), but cannot start with a digit. |
Method |
|---|
+ (void)setUserProfile:(nonnull NSString *)name setValue:(nullable NSString *)value 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 |
|---|
+ (nullable NSDictionary<NSString *, id> *)userProfiles:(BOOL)preDefined Obtains automatically collected or custom user attributes. NOTE: This method cannot obtain the following automatically collected attributes: AAID and IDFA. |
Parameters
Name | Description |
|---|---|
preDefined | Indicates whether to obtain automatically collected or custom user attributes.
|
Returns
Type | Description |
|---|---|
NSDictionary<NSString *, id> | Automatically collected or custom user attributes. |
Method |
|---|
+ (void)setAnalyticsEnabled:(BOOL)enabled Sets whether to enable event tracking. If this function is disabled, all cached data will be reported and no data will be recorded. NOTE:
|
Parameters
Name | Description |
|---|---|
enabled | Indicates whether to enable event tracking. The default value is YES.
|
Sample code:
The following code is used to disable event tracking.
-(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Override point for customization after app launch.
[HiAnalytics config];
[HiAnalytics setAnalyticsEnabled:NO];
return YES;
} Method |
|---|
+ (nonnull NSString *)AAID Obtains the AAID. |
Returns
Type | Description |
|---|---|
NSString * | AAID. |
Method |
|---|
+ (void)setUserId:(nullable NSString *)userId Sets a user ID. When this method is called, a new session will be 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 nil. |
Parameters
Name | Description |
|---|---|
userId | Anonymous user ID, a string containing a maximum of 256 characters. It is associated with the user data by Analytics Kit. Only you can use this ID to trace a specific user, while Analytics Kit cannot. The value cannot be empty. 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 |
|---|
+ (void)setSessionDuration:(NSTimeInterval)milliseconds 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 |
|---|---|
milliseconds | 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 |
|---|
+ (void)clearCachedData Clears all the collected data in the local cache, including data that failed to be sent. Data configured through the following APIs will be cleared: NOTE: Calling this method will reset the AAID. In Analytics Kit 6.0.0 and later versions, calling this method will also reset the user ID. |
Method |
|---|
+ (void)setRestrictionEnabled:(BOOL)enabled Sets whether to disable data analysis. The default value is NO, which indicates that data analysis is enabled. |
Parameters
Name | Description |
|---|---|
enabled | Indicates whether to disable data analysis. The default value is NO.
|
Method |
|---|
+ (BOOL)isRestrictionEnabled Checks whether data analysis is disabled. |
Returns
Type | Description |
|---|---|
BOOL | YES if data analysis is disabled; NO otherwise. |
Method |
|---|
+ (void)setCollectAdsIdEnabled:(BOOL)isEnabled Sets whether to collect IDFAs. |
Parameters
Type | Description |
|---|---|
isEnabled | Indicates whether to collect IDFAs.
|
Method |
|---|
+ (void)addDefaultEventParams:(nullable NSDictionary<NSString *, id> *)params 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. NOTE:
|
Method |
|---|
+ (void)setMinActivitySession:(NSTimeInterval)milliseconds Sets the minimum interval for refreshing a session when your app is running in the background. When the app is running in the background for a period of time longer than the specified threshold, a new session will be generated when the app switches to the foreground. |
Parameters
Name | Description |
|---|---|
milliseconds | Minimum interval for refreshing a session, 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 30000 (that is, 30 seconds). |