Boost your game with Huawei Analytics in Unity!

Samet Güzel
Huawei Developers
Published in
5 min readMay 10, 2021
Photo by @SpaceX on Unsplash

📖 Introduction 📖

In this article, I’ll be showing how to implement HMS Unity Plugin into your project and how to get started with Huawei Analytics Service!

I’ll be implementing HMS Unity Plugin on an old tutorial project called Space Shooter that Unity provided years ago. We’ll be putting events in specific places to improve our game’s user experience.

🚧 Getting Started 🚧

First, we need to create a project on AGC which is explained here. After that, we need to install the appropriate Unity package depending on our Unity version. You can find released versions here. I’ll be using the current latest version which is v2.0.4 for my Unity 2020 version. As a final step before coding, we need to import HMS Unity Plugin into our project explained here.

✨ Enabling Analytics Service ✨

First, let’s enable Analytics Service in AGC. Go to Project Settings then Manage APIs section on AGC. Find HUAWEI Analytics then make sure that it is enabled.

Enabling Huawei Analytics on AGC

After that, browse into HUAWEI Analytics then Project overview. Then click on Enable Analytics service.

Enabling Analytics Service.

It redirects us to a page where we need to set Data processing location, Time Zone and Currency. After setting these values, click on the Finish button. This will conclude our progress on the AGC side for Enabling Analytics Service.

Analytics Service Settings

Now, let's configure our Unity project. Before starting to code, let's enable Analytics Kit in our Unity project. You can simply follow Huawei > Kit Settings in Unity menu items.

Huawei Kit Settings Menu Item

Once we click on Kit Settings, we get presented by HMS Settings Window. Just by clicking on the Analytics checkbox, we’ve enabled the Analytics Kit in our project successfully! It’ll also create an object called HMSAnalyticsManager in our current scene. This object has the DontDestroyOnLoad method called inside so we don’t need to worry about this object being destroyed when we change the scene.

HMS Settings Window

⌨️ Coding ⌨️

There is only one method that we need to call to use Analytics Kit. It is called SendEventWithBundle.

I have a Coroutine that is handling Wave management in my game. For my game logic, I measure the player’s survival time within that wave then report this using Analytics Kit to see at which wave the player is struggling to complete. Thanks to that info, I can tweak game parameters for waves. Here is my spawn wave logic.

💻 App Debugging 💻

Huawei Analytics has a feature called App Debugging. You can enable the debug mode to view the event records in real-time, observe the results and adjust the event reporting policies. This feature is recommended to debug and test your analytics events.

To use app debugging, we need to have a device plugged into our computer. Then, we simply call a command via command prompt.

To enable App Debugging, use the following command.

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

Replace package_name with your own package name that you used in Unity. You can find it under File > Build Settings > Player Settings > Other Settings > Identification > Package Name

To disable App Debugging, use the following command.

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

After enabling app debugging, we should see the device in HUAWEI Analytics > App Debugging on AGC.

App Debugging Device List

After playing the game a bit and your SendEventWithBundle methods get triggered, we should see some events registered on the App Debugging page.

App Debugging Event List

In my SpawnWaves method, I was registering the event name called WaveTime. As a parameter, I was passing Wave number with how many seconds that player survived. When we click on WaveTime on the Hot Events section, we can see that I’ve survived Wave 5 for 9 seconds. There are other events called Wave3 and Wave2 with survival time as parameters as well.

WaveTime Event Details

With this result, we’ve successfully sent the analytics events from our game to AGC. Now we need to wait and collect some analytics so that we can analyze events.

💡 Conclusion 💡

We learned how to create projects on AGC, how to implement HMS Unity Plugin, and how to enable/use Huawei Analytics services.

After collecting some analytics, we can go into HUAWEI Analytics > Behaviour analysis > Event analytics to analyze our events.

App Debugging will prevent events to register into the actual event list on our AGC since App Debugging is only for debugging purposes. Be sure to disable App Debugging and play the game in that state in order to collect real event data.

For this Unity project, I can analyze and see in which waves users are struggling to complete and how many seconds they survive in the waves. By looking at the Event analysis, I can tweak the hard waves and make it easier for users so that they can have a better user experience in the game.

For more examples of how to use analytics on games;

  • You can measure how long users are playing the game and closing it.
  • You can detect at which wave users are usually closing the game and maybe they are getting bored at a certain wave.
  • You can get an average shooting laser count for a wave.

I hope this article has shown the importance of having analytics and boosting your game to the next level!

Don’t hesitate to ask questions

👇 References 👇

--

--