Using Huawei Dynamic Tag Manager To Send Analytics Data To Firebase

Erman Derici
Huawei Developers
Published in
4 min readOct 4, 2023
Analytics are an important part of any commercial product

Hello,
In this article, I will explain how you can use Huawei Dynamic Tag Manager (DTM) to handle analytics data and share this data with other platforms, mainly Firebase.

Please note that I will be skipping some steps (such as creating your project in AppGallery and enabling the necessary services, and downloading the service.json files) for the sake of simplicity. You can access their respective guides in the references section at the bottom.

Introduction

Huawei DTM is a tag management system that allows you to track your tagged events or analytics entries across different platforms. It works by sending the tagged event to the related analytics platforms and providing them with data gathered from Huawei Analytics. Huawei Analytics is required to integrate Huawei DTM into your app.

Huawei DTM can be used with various analytics platforms, these include but are not limited to:

  • Google Analytics — Universal Analytics
  • Google Analytics — Firebase
  • Google Ads Remarketing
  • AppsFlyer
  • Singular

In this article, we will be focusing on Google Analytics — Firebase integration. So let’s get started.

Source: https://giphy.com/gifs/BpGWitbFZflfSUYuZ9

Integration

First, you will need to import Huawei Analytics and Huawei DTM to your project. Since we are going to be sending data to Firebase, we will need to import Firebase Analytics as well. Again, I am assuming you have handled the other configurations such as Firebase BOM and AGC plugin.

Add the required dependencies to your build.gradle file:

implementation 'com.huawei.hms:hianalytics:6.9.0.300'
implementation 'com.huawei.hms:dtm-api:6.6.0.305'
implementation("com.google.firebase:firebase-analytics-ktx")

Initialize the required SDKs in your first activity class:

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Obtain the HiAnalyticsInstance instance.
val instance = HiAnalytics.getInstance(this)
val firebaseAnalytics = Firebase.analytics
}

For now, our client development is done. We will configure our settings in the AppGallery Connect console and then return back to our app to finish coding.

We start off by creating a configuration for DTM:

Add a configuration

Now I will create a tag on the console. You can access this page by navigating to Dynamic Tag Manager > Workspace > Tag > Create

Navigating to tag creation

While creating a tag, choose the extension as Firebase:

Tag creation extension

Next up is how we trigger this condition. Let’s add a condition to this tag:

Adding condition

As we have not created a condition before, we need to create a new condition. For the sake of simplicity, I will be using a default automatic event:

Create condition

Now we can select our condition in the previous tag creation page and finish the tag creation:

Finish tag creation

Now we can navigate back to our workspace and create a new version:

Create version

This concludes the mandatory parts we need to do in AppGallery Connect.

Now we can run our app, launch an activity and we should see the event in our Google Analytics dashboard:

Event on Google Analytics

Extra

This is not related to our use case, but I figured it would be nice to show you how you can trigger a custom event. We need to create a bundle object and put our desired tags in it. Then we can report the event to the console:

// Customize an event to report.
// Set the custom event name to Purchase.
val eventName = "Purchase"
// Customize event parameters.
val bundle = Bundle()
bundle.apply {
// Set a value of the Double type.
putDouble("price", 9.99)
// Set a value of the Long type.
putLong("quantity", 100L)
// Set a value of the String type.
putString("currency", "CNY")
}
// Report events.
instance?.let {
it.onEvent(eventName, bundle)
}

This will report an event named Purchase to Huawei Analytics.

Conclusion

Huawei DTM is a powerful tag management tool that allows you to have a single tag management system in your app to manage various analytics SDKs. This way, you won’t have to worry about integrating multiple analytics SDKs into your app and manually handle all events for each analytics SDK. DTM handles those and automatically sends the events to your analytics dashboard.

I have shown how you can setup Huawei DTM in your application and send an event to your Google Analytics dashboard. I hope this has been useful as a starter guide, you can customize your tag, condition, and other configurations to suit your needs.

References

--

--