DTM to Firebase Analytics

irene83018774 profile image Irene ・5 min read

As we all know that Huawei has this cool Dynamic Tag Manager (DTM) kit to allow developers to deploy, update and configure tag conveniently and securely on web-based UI. But do you know that DTM also facilitate developers to track specific events and report data to powerful analysis capabilities of Huawei Analytics as well as third party analysis platforms including Firebase Analytics. Yes, you read it correctly with robust DTM tool you can send events data to Firebase Analytics without any additional code or efforts. It means that if developers already using Firebase analytics for analyzing user behaviors and logging specific events for their app and they don’t want to switch to more powerful HMS analytics kit then they just to need configure DTM kit in their app and they are all set to send log events to Firebase Analytics from Huawei devices. So, let’s demonstrate that by developing demo app and integrating DTM kit in it.

How to Integrate?

DTM kit can be easily integrated in our app by following these steps:


  • Verified Developer account in Huawei Developer website
  • Desktop or laptop with installed JDK 1.8, Android Studio and Android SDK package

Preparations Needed

  • Create project in Android studio
  • Create SHA Key. Please refer to this article in order to generate your SHA Key
  • Create an app in AppGallery Connect (AGC). Project will be automatically created for your app as well.
  • Choose your preferred data storage location. Provide package name of your Android project to AGC app and put SHA key in app information section
  • Enable Analytics service in AGC. To do so, first go to your app > Develop tab > Manage APIs tab and enable Analytics Kit. After that Go to Huawei Analytics > Overview > Project overview and click on Enable Analytics service button in order to use the Advanced Analytics functions.
  • Now download auto-generated agconnect-services.json from App information section of Develop tab of your app. Store downloaded JSON file into app directory of your Android project.
  • Configure Analytics and DTM Kit dependencies in project as well as app level build.gradle files.

First, go to build.gradle file of your project and provide following maven url inside the repositories of buildscript and allprojects: maven {url 'https://developer.huawei.com/repo/'}. Also, add AppGallery Connect dependencies and Google serveices to dependencies scope under buildscript scope.
classpath 'com.huawei.agconnect:agcp:'
classpath 'com.google.gms:google-services:4.3.0'

  • Second, go to build.gradle file of your app and put bellow plugin and dependency in dependencies section. apply plugin: 'com.huawei.agconnect' apply plugin: 'com.google.gms.google-services' implementation 'com.huawei.hms:hianalytics: 4.0.3300' implementation 'com.huawei.hms:dtm-api:' implementation 'com.google.firebase:firebase-analytics:17.4.3'
  • Finally, click on Sync Now to finalized configuration
  • Also, remember to keep your google-services.json file that you will have from firebase into app directory of your Android project.
  • Configure proguard-rule.pro file to ensure that the Analytics and DTM kit is not obfuscated:
-keep interface com.huawei.hms.analytics.type.HAEventType{*;}   
-keep interface com.huawei.hms.analytics.type.HAParamType{*;}
-keep class com.huawei.hms.analytics.HiAnalyticsTools{
public static void enableLog();
public static void enableLog(int);
-keep class com.huawei.hms.analytics.HiAnalyticsInstance{*;}
-keep class com.huawei.hms.analytics.HiAnalytics{*;}
-keep class com.huawei.hms.feature.** {
public *;
-keep public class com.huawei.hms.common.** {
public *;
-keep class com.huawei.hms.analytics.internal.filter.EventFilter{
public void logFilteredEvent(java.lang.String, android.os.Bundle);
public java.lang.String getUserProfile(java.lang.String);
-keep public class com.huawei.hms.dtm.EventFilter {
public <fields>;
public <methods>;

Let’s develop

At this moment, we are all set to dive into some coding of our demo app in order to report some custom events to Firebase Analytics kits. It’s just a simple activity which is available on GitHub in DigitalTagMangActivity

DTM Setup

To setup DTM service in our app, first we need to sign in to AppGalley Connect and then go to "My Projects > Growing > Dynamic Tag Manager and click on Create configuration button.
Alt Text
And there provide relevant information that you would like to have for your app.
Alt Text
To report your custom events to Huawei Analytics keep radio button checked. Once you click on Ok button, created configuration will be shown on configuration management page.
Alt Text
Now click on your created configuration and go to Variable tab where you can create custom variables. In my case, I am creating custom variable of country and setting default value as “Finland”.
Alt Text
Then, we move to Condition tab where we set the condition to report events. If you would like to report all events then just select “All events” trigger. However, I only want to report events which matches my condition as shown below:
Alt Text
After that go to Tag tab where actually magic happens. Here, we specify which third party platform we would like to send our logs to. Please select Firebase and add parameter(s) of your choice. I have added parameter ‘isHuawei’ to filter out specific events in Analytics Dashboard. I have also added condition with my tag that only report ‘isHuawei’ parameter to Firebase when my country condition is valid i.e. Finland as seen in the next figure.
Alt Text
In the end, go to Version tab and give appropriate name and release it. There can be only one released version so when you create new version, older version gets obsolete.
Alt Text
Now download DTM file from versioning tab and place it in app\src\main\assets\containers folder. Please create relevant folders if they do not exists already.
Alt Text
At this moment, we are all ready and have successfully integrated DTM in our app. Now run app and go to DigitalTagManagActivity where our log events will be sent to Firebase Analytics. if you happen to use Huawei Mobile Services (HMS) only device please ignore this message in logcat “Google Play services missing or without correct permission”

We can use debug mode too in order to test whether our log events being sent to Firebase or not in real time. First we need to activate our debug mode in terminal using following command:
adb shell setprop debug.firebase.analytics.app com.huawei.codelabkit

Then please go to firebase console > Your Project > Debug view. If everything is working correctly then you should be able to see following details:
Alt Text
Also, at the same time we can see our event logs in app debugging in Huawei Analytics too as shown below:
Alt Text
And this is how our Firebase Analytics Dashboard looks like of our demo app.
Alt Text

There you have it! This feature will work with HMS only devices and it will also work with HMS + Google Mobile Services (GMS) devices as well. Please feel free to post your questions if you face any difficulty I would be more than happy to answer to the best of my knowledge.


Posted on by:


markdown guide