目录

HUAWEI Analytics Kit is based on the event analytics data model.

The analytics data model uses the Event-Param-User model to record data, describes events using parameters, and describes the characteristics of users.

TermMeaningDescription

Event

Event

An event describes a specific task completed by a user at a location using a method at a time, including key elements such as who, when, where, how, and what.

Param

Parameter

Associated parameters reported in events, for example, the product name and product price parameters in the event of a product being added to the shopping cart. These parameters can be used for subsequent in-depth analytics.

UserProfiles

User attribute

List of user attributes. Common user attributes include the ODID, device model, app version, and custom user attributes such as food preferences.

HUAWEI Analytics Kit collects the AAID that is allocated by the HMS Instance ID to each app instance installed on the device. The AAID is used for connecting various Huawei services, such as HUAWEI PUSH Kit, HUAWEI Analytics Kit, and remote configurations.

The AAID will be reset in the following scenarios:

Procedure

1. Initialize the HMS Core Analytics SDK.

After the agconnect-services.plist file is imported successfully, initialize AppDelegate through the config interface.

Objective C code example: Perform initialization in AppDelegate.m.

  1. #import "AppDelegate.h"
  2. #import <HiAnalytics/HiAnalytics.h>
  3. @interface AppDelegate ()
  4. @end
  5. @implementation AppDelegate
  6. ...
  7. - (BOOL)Application:(UIApplication *)Application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  8.    // Override point for customization after Application launch.
  9.  [HiAnalytics config];//Initialization
  10.    return YES;
  11. }
  12. ...
  13. @end

Swift code example: Perform initialization in AppDelegate.swift.

  1. import UIKit
  2. import HiAnalytics
  3. @UIApplicationMain
  4. class AppDelegate: UIResponder, UIApplicationDelegate {
  5. ...
  6. func Application(_ Application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool  {
  7.        // Override point for customization after Application launch.
  8.       HiAnalytics.config();//Initialization
  9.        return true
  10. }
  11. ...
  12. }

2. Record defined events using the onEvent API. For definitions of the events, please refer to Event Description.

3. Call APIs of HUAWEI Analytics Kit to implement the corresponding functions. For details, please refer to API Reference. For example, call the setUserProfile API to set user attributes.

Sample Code

Insert tracing points in proper position of the code.

  1. //Set user attributes.
  2. [HiAnalytics setUserProfile:@"userProfile1" setValue:@"userProfileValue1"];
  3. [HiAnalytics setUserProfile:@"userProfile2" setValue:@"userProfileValue2"];
  4. //Customize tracing points and add tracing points in the proper position of the code.[HiAnalytics onEvent:@"customEventName"

  5. setParams:@{@"key1":@"value1",@"key2":@"value2"}];

Using the Debug Mode

During the development, you can use DebugView to view the event records in real time, observe the results, and adjust the event tracing scheme.

Enabling/Disabling the Debug Mode

1. To enable the debug mode:

Choose Product > Scheme > Edit Scheme from the Xcode menu. On the Arguments page, click + to add the -HADebugEnabled parameter. After the parameter is added, click Close to save the setting.

  1. -HADebugEnabled

Note:
The debug mode remains enabled until you explicitly disable it by setting the -HADebugDisabled parameter.

2. To disable the debug mode:

  1. -HADebugDisabled

Successfully reported data is displayed on Huawei Developers in real time, as shown in the figure below.

For details about how to view analysis data on Huawei Developers, please refer to App Debugging.

Adjusting the Log Level by Adding Arguments

You can adjust the log level by adding arguments.

The available options include -HALogLevelDebug, -HALogLevelInfo, -HALogLevelWarn, and -HALogLevelError. For example, if you want to set the log level to HALogLevelDebug:

Choose Product > Scheme > Edit Scheme from the Xcode menu. On the Arguments page, click + to add the -HALogLevelDebug parameter. After the parameter is added, click Close to save the setting.

  1. -HALogLevelDebug