目录

Client Development

Configuring the Code

  1. Import the header file <HiAnalytics/HiAnalytics.h> to AppDelegate.m, and initialize HiAnalytics.
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Initialize HUAWEI Analytics.
    [HiAnalytics config]; 
    return YES;
    }
  2. (Optional) Insert code for reporting events in the proper position.

    Skip this step if you use the visual event function to add events.

    // Customize an event to report.
    // Set the custom event name to Purchase.
    // Set customKey and customValue to specify a custom event key and value, respectively.
     NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; 
    // Customize parameters.
    [params setObject:@"9.99" forKey:@"price"];  
    [params setObject:@"100L" forKey:@"quantity"];  
    [params setObject:@"CNY" forKey:@"currency"];  
    // Report the event.
    if (self.customKey.text.length >0 && self.customValue.text.length >0) { [1] 
    [params setObject:self.customValue.text forKey:self.customKey.text];
     }
    [HiAnalytics onEvent:self.eventName.text setParams:params];

    The following figure shows the demo app screen in the codelab.

Using the Debug Mode

During development, you can enable the debug mode to view the event records in real time, observe the results, and adjust the event tracking scheme as needed.

  • HUAWEI Analytics template

    Enabling the debug mode: Select Arguments in Edit scheme, and add -HADebugEnabled.

    Disabling the debug mode: Select Arguments in Edit scheme, and delete -HADebugEnabled.

  • Google Analytics (Firebase) template

    Enabling the debug mode: Select Arguments in Edit scheme, and add -FIRAnalyticsDebugEnabled and -FIRDebugEnabled.

    Disabling the debug mode: Select Arguments in Edit scheme, and delete -FIRAnalyticsDebugEnabled and -FIRDebugEnabled.

  • Other templates (such as Adjust and AppsFlyer)

    Enabling the debug mode: Select Arguments in Edit scheme, and add -DTMDebugEnable and -DTMLogLevelDebug.

    Disabling the debug mode: Select Arguments in Edit scheme, and delete -DTMDebugEnable and -DTMLogLevelDebug.

For details about debugging operations in AppGallery Connect, please refer to App Debugging.

  1. Select Arguments in Edit scheme in Xcode and add the relevant items on the screenshot below to enable the debug mode.

    After the debug mode is enabled, all events will be reported in real time.

  2. Delete these items to disable the debug mode.

    Successfully reported data is displayed on HUAWEI Analytics in real time, as shown in the screenshots below.