👨🏼‍💻Collect Page Statistics with Huawei Analytics Kit in Single Activity Architecture

Abdurrahim Çillioğlu
Huawei Developers
Published in
5 min readJun 24, 2022

--

Huawei Analytics

Introduction

Hi everyone! In this article, we will explore how to collect page data with Huawei Analytics Kit in Single Activity Architecture. Analytics Kit provides us free data analysis solution. As a result of the analysis, we can increase the in-app experience of the users and reach more users.

What is the Huawei Analytics Kit?

Analytics Kit is a one-stop user behavior analysis platform for products such as mobile apps, web apps, quick apps, quick games, and mini-programs. It offers scenario-specific data collection, management, analysis, and usage, helping enterprises achieve effective user acquisition, product optimization, precise operations, and business growth.
Some advantages of Analytics Kit:

  • Simplified access
  • Intelligent analysis
  • Flexible configuration
  • Seamless integration

As you can see, the Analytics Kit has many excellent features. However, In this article, we will focus on the Page Analysis feature.

Why Should We Use Page Analysis?

Page Analysis displays the number of times users visit each page in your app, the average time they spend on each page, and both indications as a proportion of all page views. Gathering this accurate data help us to serve our customers better.

If we modified a page, the data can measure whether it improves the user experience or not. Or, we can determine the pages that users visit the most and use this information in future developments. We can also learn which pages need improvement with Page Analysis.

To summarize, screen analysis gives us the following information:

  • Percentage of visits
  • Stay duration per time
  • Page visits
  • Percentage of stay duration per time

A Quick Reminder: Single Activity Architecture

As you already know, Activities are entry points to our apps. We may have one or more activities in our app.

“An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View). While activities are often presented to the user as full-screen windows …”, according to Official Android Doc.

Single-Activity Architecture is the architecture that has only one Activity or a relatively small number of Activities. So, what will we use instead of Activity? The answer is Fragment. A fragment is a reusable part of your app’s user interface. A fragment has its own layout and lifetime. Also, it can handle its own input events. Some of the benefits of using Single Activity Architecture:

  • The transactions between fragments are fast than creating new activities.
  • Android Jetpack’s Navigation component allows us to manage fragment transactions easily.
  • Easy handling of your app’s Toolbar and Navigation Drawer.
  • Implementing and handling deep linking.

In Analytics Kit, the automatic collection is supported for Activity pages. But for non-activity pages like Fragments, we need to call some methods.

1-) HMS Core Integration

We’re not going to go into the details of integrating Huawei HMS Core into a project. You can follow the instructions to integrate HMS Core into your project via official docs or codelab. Also, you can learn all the details from this Medium article.

And, we need to enable Analytics Service and API.

2-) Adding Dependency

Add the necessary dependencies to build.gradle (app level).
It may not be the latest version of Analytics Kit. You can check the latest version from here.

3-) Initialize the Analytics SDK

Initialize the Analytics SDK in our Application Class.

4-) Customize a Page Event

In Analytics Kit, the automatic collection is supported for Activity pages. But for non-activity pages such as Fragments, we should call pageStart and pageEnd methods.

Data Collection — Activity vs Non-Activity

pageStart defines a page entry event. After calling this method, we should call the pageEnd method.

Please make sure you don’t use pageStart and pageEnd in your activity pages. If you use it in your activities, statistics on page entry and exit events will be inaccurate.

5-) Viewing the Summary Data of All Pages

After all implementation processes, we are ready to view our reports. First, sign in to AppGallery Connect and click My projects. Find your project, and click your app. Go to HUAWEI Analytics > Behavior analysis > Page analysis. On this screen, you can view the summary data of all pages.

Page Analysis Screen

We have mentioned above which data you can access from this table. You can also apply various filters or select a time segment to obtain more specific data.

6-) Page Management

Go to HUAWEI Analytics > Management > Pages. You can manage pages by adding, editing, or deleting pages.

Page Management Screen

Tips & Tricks

  • You can add descriptions from the Pages Management to make page events more meaningful.

Conclusion

In this article, we have learned how to collect page statistics with Huawei Analytics Kit. And we’ve looked at how to view the page statistics. Please do not hesitate to ask your questions as a comment.
Thank you for your time and dedication. I hope it was helpful. See you in other articles!

References

--

--