Reporting Events to Google Analytics Using DTM

sujith E
Huawei Developers
Published in
4 min readApr 27, 2021

As an operator, one daily routine is data analysis of your app’s user behavior data. For example, you may need to obtain the conversion data of each stage of the service process for users acquired from different channels, as well as payment data from your app, and then report the data obtained to an analytics platform to analyze your app performance. In practice, requirements may keep changing. Let’s say you change the analytics platform to Google Analytics for the AddProduct2Cart event. You’d need to request developers to modify the code and release a new app version. The event can be reported to Google Analytics only after users have updated their app to this new version. The whole process needs a lot of time and labor.

How could you report an event to an analytics platform quickly and without modifying the code?

Dynamic Tag Manager (DTM) is your answer. With DTM, you can set event trigger conditions and configure and update tags quickly on a web-based UI, and report the event data to an analytics platform.

In this article, you will learn about how to report the $AddProduct2Cart event to Google Analytics using DTM.

Only two steps are required for reporting events to Google Analytics:

1. Modify the DTM configuration for the event $AddProduct2Cart on the Dynamic Tag Manager page in AppGallery Connect to report the event to Google Analytics.

2. Create and release a new DTM configuration version.

Before that, integrate the DTM SDK and the Analytics SDK for your app and complete tracking configuration for the $AddProduct2Cart event as follows:

<p style=”line-height: 1.5em;”>Bundle bundle = new Bundle();
bundle.putString(PRODUCTID, “xxx”);
bundle.putString(PRODUCTNAME, “xxx”);
HiAnalytics.getInstance(context).onEvent(HAEventType.ADDPRODUCT2CART, bundle);</p>

The detailed operations are as follows:

1. Modify the DTM configuration.

1.1 Configure variables.

Go to Grow > Dynamic Tag Manager > Variable. Click Configure, select Event Name, and click OK.

1.2 Create a condition.

On the Condition page, click Create. On the page displayed, enter a condition name, select Custom for Type, and select Some events for Trigger. Then, set Variable to Event Name, Operator to Equals, and Value to $AddProduct2Cart.

1.3 Create a tag.

On the Tag page, click Create to create a tag for Google Analytics to track events. Configure the tag as follows:

Name: custom tag name

Extension: Google Analytics: Universal Analytics

Tracking ID: unique ID provided by Google Analytics for tracking data, in the format of UA-XXXXXXXX-X

Tracking type: Event

Event type: Click

Event operation: Add2Cart

Add the condition you have created in the Conditions area.

2. Create and release a new DTM configuration version.

On the Version page, click Create to create a new DTM configuration version. Select Create and release version so that the app with the DTM SDK integrated will periodically check and download the latest configuration and report events according to the configuration.

The configuration successfully created will be released automatically.

3. View data in Google Analytics.

3.1 Download the latest configuration version.

The default interval between two downloads of the DTM configuration is 6 hours. To download the latest configuration immediately, clear the app cache and restart the app.

3.2 Report data in real time

Events are reported every 10 minutes by default when the app is running. To report events in real time, run the following command:

adb shell setprop debug.huawei.hms.dtm.app <package_name>

3.3 View data in Google Analytics.

Add a product to the shopping cart in your app. Then, wait for several minutes and go to Real-time > Events in Google Analytics to view the data of this event.

You will find that the event category is Click and the operation is Add2Cart, which is consistent with your DTM configuration. That means, your DTM configuration is valid.

For more details, you can go to>>

For more on HUAWEI Prediction, visit>>

For more details, you can go to:

l Our official website

l Our Development Documentation page, to find the documents you need

l Reddit to join our developer discussion

l GitHub to download demos and sample codes

l Stack Overflow to solve any integration problems

--

--