How to integrate Analytics kit in Unity Game development
By: Shiddalingeshwar M S
Tags: Analytics, Unity, Hms Core, Huawei Mobile Service, Huawei Developers

How to integrate Analytics kit in Unity Game development

In this article, you will learn about Integration of Analytics Kit in your Unity Project .Analytics kit helps you to get the various information about the application installation usage, users and custom events can track. Shiddalingeshwar M S Dec 23, 2020·4 min read

Introduction

In this article, you will learn about Integration of Analytics Kit in your Unity Project .Analytics kit helps you to get the various information about the application installation usage, users and custom events can track.

Requirements:

1. Unity Software installed in the machine

2. Huawei device

3. Visual Studio or Visual code

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.

Follow the steps:

1. Creating Unity Project

· Open Unity Hub.

· Click NEW, select 2D, Project Name and Location.

· Click CREATE, as follows:

2. Click Asset Store, search Huawei HMS Core App Services and click Import, as follows.

3. Once import is successful, verify directory in Assets > Huawei HMS Core App Services path, as follows.

4. Choose Edit > Project Settings > Player and edit the required options in Other Settings, as follows.

Enter Package Name, it should same as agconnect-service.json.

5. Choose Edit > Project Settings > Player and edit the required options in Publishing Settings, as follows.

6. Download agconnect-services.json and copy and paste to Assets > Plugins > Android, and Assets > Plugins > Android>assets as follows.

7. Create 2D Object, UI Boundary (sprites), canvas status text and add ball image in sprites folder

Right-click select Create > Sprites > Square to create Boundary sprites

To create bound effect create Material 2D and attach to Ball.

8. Create Assets> Scripts folder and create a class and Attach the script to Game Object.

9. For debugging mode, run the below command:

adb shell setprop debug.huawei.hms.analytics.app package_name

10. Generating SHA-256 certificate fingerprint

keytool -list -v -keystore D:\Unity\projects_unity\file_name.keystore -alias alias_name

To generate SHA-256 fingerprint key use above command line and hit enter , it will ask for the password enter the password and do not forget to add SHA-256 certificate fingerprint in ag-connect console in General Information tab.

11. To know more about HMS Core, follow the URL.

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

12. Build and run the application.

To build and run the project for android first Switch Platform and then choose Build to generate apk or choose Build Run to build and run on real device connected.

Choose File >> Build Settings >> Build or Build and Run

Tips & Tricks

1. Download latest HMS plugin.

2. HMS plugin v1.2.0 supports 7 kits.

3. HMS Unity Plugin v1.1.2 supports 5 kits.

Conclusion

In this Article, We have learned how to integrate Analytics Kit in Unity based Game and check desired output/events in ag-connect console once event triggered from your application.

Thanks for reading this article. I hope you learnt something new today, if you found this article helpful and enjoyed coding. Please like and comment your queries.

References

https://developer.huawei.com/consumer/en/hms