Effortless integration of Analytics Kit in Unity

Overview

In this article, I will create a demo game and integrate Huawei Analytics Kit. A developer can keep keen eyes on application usages and easily track the events such as installation and other custom events.

Service Introduction

Analytics Kit collects a user’s activity and usage of an application so that developer can analyze the user’s behaviour based on the app event.

Analytics Kit offers a rich array of preset analytics models (Event, Behaviour, Audience, Funnel, Retention, Real-Time) that help you to gain an in-depth insight into your users, products, and content. With this insight, you can then take a data-driven approach to make informed decisions for product and marketing optimizations.

HUAWEI Analytics Kit identifies users and collects statistics on users by an anonymous application identifier (AAID). The AAID is reset in the following scenarios:

1) Uninstall or reinstall the app.

2) The user clears the app data.

After the AAID is reset, the user will be counted as a new user.

There are 3 types of events: Automatically collected, predefined, and custom.

  • Automatically collected events are collected from the moment you enable the kit in your code. Event IDs are already reserved by HUAWEI Analytics Kit and cannot be reused.
  • Predefined events include their own Event IDs which are predefined by the HMS Core Analytics SDK based on common application scenarios. The ID of a custom event cannot be the same as a predefined event’s ID. If so, you will create a predefined event instead of a custom event.
  • Custom events are the events that you can create for your own requirements.

Prerequisite

1. Unity Engine (Installed in the system)

2. Huawei phone

3. Visual Studio 2019

4. Android SDK & NDK (Build and Run)

Integration process

1. Sign In and Create or Choose a project on AppGallery Connect portal.

2. Navigate to Project settings and download the configuration file.

3. Enable Analytics Kit from Manage APIs section.

Game Development

1. Create a new game in Unity.

2. Now add game components and let us start game development.

3. Download HMS Unity Plugin from below site.

https://github.com/EvilMindDevs/hms-unity-plugin/releases

4. Open Unity Engine and import the downloaded HMS Plugin.

Choose Assets > Import Package> Custom Package

5. Choose Huawei > App Gallery.

6. Provide the AppId and other details from agconnect-service.json file and click configure Manifest.

7. Download and import HMS into our project via Unity Asset Store.

Click Asset Store and search HMS.

Download then import HMS to project.

8. Now we will be able to see HMS Core Services in the Asset folder.

9. Create Huawei Analytics Kit based scripts.

I have created AnalyticsDemoManager.cs file in which integrated Huawei Analytics kit based functionality.

Click on AnalyticsDemoManager.cs and open in Visual Studio 2019

Result

Let us build the apk and install in android device.

Tips and Tricks

1. HMS plugin v1.2.0 supports 7 kits.

2. Ensure that you have installed HMS Core (APK) 3.0.0.300 or later.

3. You can collect and report custom events through coding.

4. You can set a maximum of 25 user attributes.

5. You can automate event collection and session calculation with predefined event IDs and parameters.

Conclusion

In this article, we have learned how to integrate Huawei Analytics Kit in Unity-based Game.

The developer can analyse the user’s behaviour based on the game’s event and custom events.

Thanks for reading this article. Be sure to like and comments to this article if you found it helpful. It means a lot to me.

References

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050745149

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store