Expert: Implementation of Android Work Manager in HMS/GMS Android App with Firebase Authentication and Analytics Integration

Overview

In this article, I will create an Android Demo app which highlights use case of Google Analytics and HMS Analytics using Work Manger APIs in Single Android App. I have integrated Huawei Analytics and Google Analytics.

In this Demo Android application, User can sign in using Google or Huawei Id Login. Then send the analytics events on the respective server via Work Manager APIs in Android.

Huawei Analytics Introduction

Analytics kit is powered by Huawei which allows rich analytics models to understand user behavior and gain in-depth insights into users, products, and content. As such, you can carry out data-driven operations and make strategic decisions about app marketing and product optimization.

Analytics Kit implements the following functions using data collected from apps:

1. Provides data collection and reporting APIs for collection and reporting custom events.

2. Sets up to 25 user attributes.

3. Supports automatic event collection and session calculation as well as predefined event IDs and parameters

Google Analytics Introduction

Google Analytics collects usage and behaviour data for your app. The SDK logs two primary types of information:

Events: What is happening in your app, such as user actions, system events, or errors?

User properties: Attributes you define to describe segments of your user base, such as language preference or geographic location.

Analytics automatically logs some events and user properties, you don’t need to add any code to enable them.

Prerequisite

1. Huawei Phone

2. Android Studio

3. Google Firebase Account

4. AppGallery Account

App Gallery 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. Navigate to General Information, and then provide Data Storage location.

4. Enable Huawei Analytics.

5. Enable Dynamic Tag Manager.

6. Create Tag.

7. Configure Tag.

Firebase Integration Process

1. Create a Firebase project.

2. Choose Android as Platform.

3. Add App in your Firebase Project.

4. Download Configuration file.

5. Navigate to Google Tag Manager Console: https://tagmanager.google.com/

Create New Tag, then click to Submit.

6. Choose tag type.

7. Choose a Variable

8. Tag Configure.

9. Publish Tag

App Development

1. Create A New Project.

2. Configure Project Gradle.

3. Configure App Gradle.

4. Configure AndroidManifest.

Code Implementation

LoginActivity:

MainActivity:

GoogleWorker:

HMSWorker:

App Build Result

Tips and Tricks

1. 5.2.0 or later. If HMS Core (APK) is not installed or its version is earlier than 5.2.0, DTM functions can be normally used but the DTM SDK version cannot be updated automatically.

2. ICustomVariable and ICustomTag contain custom extensible variables and templates. You can also customize variables and templates in DTM to meet specific requirements.

Conclusion

In this article, we have learned how to integrate Google Firebase Authentication, Analytics in HMS Core based Android app using Work Manager APIs.

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

HMS Docs

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

Google Docs

https://tagmanager.google.com/

https://console.firebase.google.com/u/0/

--

--

Android Developer

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