How to Integrate HUAWEI Analytics Kit in Cordova

Mükremin Bağcı
Huawei Developers
Published in
7 min readNov 6, 2020

Hello everyone, in this article, provides example of HUAWEI Analytics Kit using the Cordova mobile application. But first, let me inform you about HUAWEI Analytics Kit a little.

HUAWEI Analytics Kit

About HUAWEI Analytics Kit

  • Offers a rich array of preset analytics models that help you gain a deeper insight into your users, products, and content.
  • Helps you gain insight into how your users behave on different platforms based on the user behavior events and user attributes reported by your app.
  • Diverse analytics models: analyzes events, behavior, audiences, funnels, retention, attribution, real-time data.
  • App Debugging: During app development, the product manager and technical team can cooperate with each other through app debugging to verify data reporting, preventing missing events and event attribute errors.
  • There are 3 types of events: automatically collected, predefined and custom.

With these insights, you can then take a data-driven approach to make informed decisions for product and marketing optimizations.

HUAWEI Analytics Kit Advantages

Privacy Statement: HUAWEI Analytics Kit does not collect users’ personal data. If your app needs to collect user data, it must do so in accordance with all applicable laws and regulations. You’ll also need to display a privacy statement, so users understand how you’re planning to use their data.

Integrating the AppGallery Connect SDK

Integrating AppGallery Connect is a prerequisite for using HUAWEI Analytics Kit is offering in your application. If you want to use the AppGallery Connect Analytics service, you must first have a AppGallery Connect developer account and integrate HMS Core in your application. You need to create an project from your developer account and then integrate the Cordova HMS Analytics Plugin into your project.

Creating an AppGallery Connect Project

1. Sign in to AppGallery Connect and select My projects.

2. Click Add project.

AppGallery Connect Add Project

3. Enter a project name and click OK.

4. After the project is created, the Project settings page is displayed. You need to add an app to the project.

Adding an App to the Project

Before you use development capabilities provided by AppGallery Connect, you need to add an app to your project first.

  1. Sign in to AppGallery Connect and select My projects.
  2. Click your project from the project list.
  3. Go to Project settings > General information, and click Add app.
AppGallery Connect Add App

4. On the Add app page, enter app information.

Platform Android
Platform iOS

5. On the Project settings page, enter SHA-256 certificate fingerpring and then download the configuration file agconnect-services.json for Android platform.

App Information - Android Platform

Generating a Signing SHA-256 Certificate Fingerprint

6. On the Project settings page, download the configuration file agconnect-services.plist for iOS platform.

App Information - iOS Platform

Integrating the HMS Analytics Plugin

You can either install the plugin through npm or by downloading it from the download page, Cordova Analytics plugin.

  • Run the following command in the project root directory of your Cordova project to install it through npm.

Add the Android platform to the Cordova project

Add the iOS platform to the Cordova project

Android and iOS Applications

Using Debug Mode

  • During the development, you can enable the debug mode to view the event records in real time, observe the results, and adjust the event reporting policies.
  • Enabled Debug Mode and after then the data is successfully reported, you can go to HUAWEI Analytics > App debugging to view the reported data, as shown in the following figure.

Android Platform

  • Run the following command to enable the debug mode:
Android Debug Mode Enabled
  • Run the following command to disable the debug mode:
Android Debug Mode Disabled

iOS Platform

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

  • 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.
iOS Debug Mode Enabled
  • To disable the debug mode
iOS Debug Mode Disabled

Viewing Debugging Event Details (Real-time Update)

  1. Sign in to AppGallery Connect and click My projects.
  2. Find your project, and click the app for which you want to view analytics data.
  3. Go to HUAWEI Analytics > App debugging.

The App debugging page displays events reported by the app in the last 60 seconds or last 30 minutes.

  • If you select Last 60 seconds, the displayed page is as follows.
  • If you select Last 30 minutes, the displayed page is as follows.

What is AAID(Anonymous Application ID)?

Anonymous device ID opened to third-party apps. Each app is allocated with a unique AAID on the same device so that statistics can be collected and analyzed for different apps (for example, statistics on the number of active users). In addition, personal data from different apps is isolated to protect user data privacy and security.

How to records event?

Records custom event

Such events can be used to meet personalized analysis requirements that cannot be met by automatically collected events and predefined events.

Note: The ID of a custom event cannot be the same as that of a predefined event. Otherwise, the custom event will be identified as a predefined event.

Records predefined event

Such events have been predefined by the HMS Core Analytics SDK based on common application scenarios. It is recommended you use predefined event IDs for event collection and analysis.

Setting User Profiles

Sets user attributes. The values of user attributes remain unchanged throughout the app lifecycle and during each session.

Note: 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.

When is the clearCacheData() method used?

It is used when deletes all collected data cached locally, including cached data that failed to be sent.

Note: AAID will be reset. Custom user attributes will be delete.

How to define a custom page?

Customizes a page entry event. The API applies only to non-activity pages because automatic collection is supported for activity pages.

Note: If this API is called for an activity page, statistics on page entry and exit events will be inaccurate.

Defines a custom page

  • After this pageStart() method is called, the pageEnd() API must be called.
  • Before this pageEnd() method is called, the pageStart() API must be called.

Conclusion

In this article you have learned how to integrate HMS Analytics to your Cordova projects, record custom events and monitor them in AppGallery Connect. You can use custom events with user attributes in your apps to see user behaviors, so that you can improve your app depend on them.

Thank you!

Other Huawei Developers Cordova Medium Publications

References

  • Stack Overflow is the best place for any programming questions. Be sure to tag your question with huawei-mobile-services.
  • GitHub is the official repository for these plugins, You can open an issue or submit your ideas.
  • Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.
  • Huawei Developer Docs is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.

If you run into a bug in our samples, please submit an issue to the GitHub repository.

--

--