【DTM】Use DTM to Report Events to Firebase - Huawei Developers

Previously, I've introduced how to quickly report app events to Google Analytics using DTM without releasing app updates. Now, the visual event tracking requirement has changed to report events to Firebase for multi-dimensional data analysis. The following uses a case to explain the process of reporting events to Firebase using DTM.
Case:
Report the $AddProduct2Cart event to Firebase using DTM.
Procedure:
1. Preparations
Before modifying the DTM configuration, ensure that you have completed the following preparations:
a. The DTM SDK has been integrated into the app.
b. The Firebase SDK has been integrated into the app.
c. The $AddProduct2Cart event has been configured for the app using the Analytics SDK.
Code:
Bundle bundle = new Bundle();
bundle.putString(PRODUCTID, "xxx");
bundle.putString(PRODUCTNAME, "xxx");
HiAnalytics.getInstance(context).onEvent(HAEventType.ADDPRODUCT2CART, bundle);
</p>
2. Modifying the DTM Configuration.
2.1 Creating a Variable
Go to Grow > Dynamic Tag Manager > Variable. Click Configure, select Event Name, and click OK.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2.2 Creating a Tag.
On the Tag page, click Create to create a Firebase tag. Configure the tag as follows:
Name: Enter a custom tag name.
Extension: Select Google Analytics (Firebase).
Event name: This parameter is optional. Select the check box and enter the renamed event name AddProduct2Cart (events reported to Firebase cannot contain the dollar sign $).
Parameters for addition: Set Key to price and Value to 1000.
Set Trigger condition to the created condition.
3. Creating and Releasing a Version.
Create and release a new configuration version on the Version page. The app with the DTM SDK integrated will periodically check and download the latest configuration version and report events according to this version.
In the Create version dialog box, select Create and release version.
4. Viewing the Reported Event on Firebase.
After completing the preceding operations, you can view the reported event on Firebase.
By default, the DTM SDK checks and downloads the latest configuration version at an interval of 6 hours. To download the latest configuration version immediately, clear the app cache and restart the app. DTM will not report events immediately if the debug mode is not enabled. Instead, events are reported every 10 minutes when the app is running. To report events immediately, run the following ADB commands:
Code:
adb shell setprop debug.huawei.hms.dtm.app <package_name>
adb shell setprop debug.firebase.analytics.app <package_name>
There may be a delay of several minutes for Firebase to receive the renamed event AddProduct2Cart triggered in the app.
Go to Analytics > DebugView to view the latest reported events.
The reported event name is AddProduct2Cart. The event has the price parameter and the parameter value is 1000, which is consistent with that set in DTM. This means that the DTM configuration has taken effect.
To learn more, please visit:
Our official website
Our development documentation page to find the documents you need
Reddit to join our developer discussion
GitHub or Gitee to download the demo and sample code
Stack Overflow to solve any integration problems
Original Source

Related

How Can I Integrate Remote Configuration of AppGallery Connect in Cordova?

Recently, it is found that AppGallery Connect Remote Configuration starts to support Cordova. The integration is rather simple, let’s have a try.If you want to quickly experience this service, see the demo on GitHub.
Integration Procedure
1. Create a project directory on your computer, run the following npm command to install Cordova.
npm install -g cordova
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2. Create a project and enable Remote Configuration.
a) Create an Android app in AppGallery, add it to a project, enable Remote Configuration, and add a parameter.
b) Run the following command to create a Cordova project. In this example, name the project RemoteConfig.
cordova create RemoteDemo com.huawei.cordova.remoteconfig RemoteConfig Creating a new cordova project.
c) Add an app platform to the project.
In the project directory, run cordova platform add android to add the Android platform.
Run cordova platform -l to view the supported platforms.
d) Go to Project settings in AppGallery Connect, download the agconnect-services.json file, and add the file to the android/app directory of your project.
e) Install the AppGallery Connect plug-in.
cordova plugin add @Cordova-plugin-agconnect/remoteconfig --save
After the plug-in is installed, you can view it in the plugins directory.
Add the AppGallery Connect plug-in address to app/build.gradle.
3. Use the Remote Configuration service.
1. Fetch data from the cloud. The data takes effect this time.
Call the fetch API to fetch parameter values from the cloud, and call the apply API to make them take effect.
You can view the fetched parameter values on the cloud in log information.
The other values displayed in log information are local ones.
2. Fetch the cloud data and make the parameter values fetched last time take effect.
Replace the fetch API with applyLastFetch to fetch data that is fetched from the cloud last time.
3. Clear the data.
Call the clearAll API to clear the cached data that is fetched earlier.
4. Fetch the value of a key from the cloud.
Call getValue to fetch related data from the cloud.
4. Compile and install an app package.
Run the cordova build android command to compile the project.
Find the APK package in the build folder in the android directory.
For more details, please check:
Cordova documentation:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html
Remote Configuration API Reference:
https://github.com/AppGalleryConnect/agc-demos/tree/main/Cordova/agc-remoteconfig-cordova
Remote Configuration Demo:
https://github.com/AppGalleryConnect/agc-demos/tree/main/Cordova/agc-remoteconfig-cordova

Initializing a Huawei Game and Implementing HUAWEI ID Sign-in Using Unity

These posts have shown the first few steps of developing a Unity-based game:
Unity Editor Installation and APK Packaging: https://forums.developer.huawei.com/forumPortal/en/topic/0204435788744370088?fid=0101187876626530001
How Can I Use the HUAWEI Game Service Demo Provided by Unity:
So far, you are able to run a game demo provided by Unity.
This post can help you further test the demo to see whether it can:
Complete some of the initialization operations.
Support HUAWEI ID sign-in and obtain player information.
After the demo test, you can write your own code by referring to the demo.
APIs provided by Unity:
APIs for game initialization:
Huawei GameService.AppInit()
HuaweiGameService.Init()
APIs for game sign-in:
HuaweiGameService.Login(ILoginListener listener)
HuaweiGameService.SilentSignIn(ILoginListener listener)
HuaweiGameService.SignOut(ILoginListener listener)
HuaweiGameService.CancelAuthorization(ICancelAuthListener listener)
APIs for obtaining player information:
HuaweiGameService.GetCurrentPlayer(bool isRealTime, IGetPlayerListener listener)
For details about these APIs, see the official documentation of Unity:
https://docs.unity.cn/cn/Packages-cn/[email protected]/manual/appgallery.html#7-api-references-list
Sign-in Process
According to Huawei’s restrictions on joint operations games (https://developer.huawei.com/consum...ry-connect-Guides/appgallerykit-devguide-game), if your game will be:
Released in the Chinese mainland, call the following APIs:
AppInit > Init > login > getCurrentPlayer
Released outside the Chinese mainland only, the following APIs are optional:
AppInit > Init > login > getCurrentPlayer
HUAWEI ID sign-in is also optional.
In this example, I was going to release an app in the Chinese mainland, so I called the related APIs.
Demo Test
Test environment requirements
Device: A Huawei phone running EMUI 10.0.0, with Android 10
HMS Core (APK) version: 5.0.4.301
HUAWEI AppGallery version: 11.0.2.302
Unity version: 2020.1.2f1c1
You can obtain the demo code by referring to the following file. When an API is called, Unity displays a message indicating the calling result, which is very convenient for you to locate faults.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Test steps
1. Start the demo. The following page is displayed.
By default, the HuaweiGameService.AppInit() API is called during app launch. The preceding message indicates that the API is successfully called.
2. Click Init. The following information is displayed.
Note: For a joint operations game, this API needs to be called when the game is launched, as required by Huawei. Unity’s demo provides a button for you to call the API.
3. Click Login, then login. The HUAWEI ID sign-in page is displayed.
Click Authorise and log in. A greeting banner and logs are displayed, indicating that the sign-in is successful.
Note: Ensure that the greeting banner is displayed, or your joint operations game may be rejected during app review.
4. Click getCurrentPlayer. The following information indicates that the player information API is called successfully.
For details about how to verify the player information, please check the official documentation:
https://developer.huawei.com/consumer/en/doc/development/HMS-References/verify-login-signature
The game sign-in is complete when the player information is approved.
Other optional APIs:
HuaweiGameService.SilentSignIn(ILoginListener listener)
Click silentSignIn. The following information indicates that the API is called successfully.
HuaweiGameService.SignOut(ILoginListener listener)
Click signOut. The following information is displayed.
HuaweiGameService.CancelAuthorization(ICancelAuthListener listener)
Click cancelAuthorization. The following information is displayed.
Click login again. The sign-in page is launched again, indicating that the authorization is canceled.

Reporting Events to Google Analytics Using DTM

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:
1
2
3
4<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.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
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
Original Source

【DTM】Verifying a New Configuration Version, with the Version Preview Function in DTM

In the last article, we discussed how the ever-changing needs of event tracking have created challenges for operations personnel, and how HUAWEI Dynamic Tag Manager (DTM) can help you report events to analytics platforms. During this process, you can finish all relevant configurations without having to pester your developer about modifying code – instead, you can just modify events to track, and create a configuration version in DTM. But one question remains: How can I verify a configuration version?
This can be done with one of the functions in DTM: previewing a version. It allows you to preview any configuration version you've created and check the reported data, which paves the way forward for releasing a configuration version.
Now let's move on to how to use this function to verify a configuration version. There are three parts involved: starting preview, verifying data, and stopping preview.
Ø Starting preview
Step 1. On the Version tab page, click the name of the version to be previewed to go to the Version details page.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Step 2. Click Preview. On the page displayed, there are three methods for starting preview:
a. Mobile browser preview
b. Scan QR code using mobile browser
c. Preview with ADB commands
Step 3. Start preview with method b, which is most convenient in most cases. Open the mobile browser to scan the QR code. The browser will then display a preview page.
Step 4. Tap Start. The browser then prompts you to open a specified app. Next, tap OPEN to open the app and start preview. A blue button will appear in the app, indicating that the preview mode has been enabled.
Blue button
Ø Verifying data
After the preview mode has been enabled, the configuration version is loaded on the mobile phone. Perform relevant operations in the app to report corresponding events, and then verify the event data reported to the specified analytics platform.
n Reporting data in real time
To report tracked events to an analytics platform in real time, you'll first need to enable the debug mode for this platform.
To report data to HUAWEI Analytics in real time, run the following command to enable the debug mode:
adb shell setprop debug.huawei.hms.analytics.app <package_name>
To report data to Firebase in real time, run the following command to enable the debug mode:
adb shell setprop debug.firebase.analytics.app <package_name>
To report data to other platforms in real time, run the following command to enable the debug mode:
adb shell setprop debug.huawei.hms.dtm.app <package_name>
n Checking data
Let's take the event of adding a product to the shopping cart as an example. After triggering this event, you'll be able to find its data in Google Analytics. This page presents an event whose Event Category is Click and Event Action is Add2Cart.
Click this event to check its details. On the page displayed, Huawei P40 Pro appears under Event Label, which indicates that the version in preview has been correctly configured.
Ø Stopping preview
Under End preview on the Preview page, three methods are provided to stop previewing a configuration version: Stop mobile browser preview, Scan QR code using mobile browser, and Stop preview with ADB commands. The blue button mentioned earlier can be used as well. Tap this button to have a popup display, which asks whether to stop preview. Tap EXIT to end the preview.
For more details, you can go to>>
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
Original Source

FAQs and Solutions Related to Analytics Kit Integration

How do I know whether the Analytics SDK has been successfully integrated or reported data? What is the meaning of key log content?​
1. Add the following code to enable the logging function before initializing the Analytics SDK:
Code:
HiAnalyticsTools.enableLog ();
2. Add the following code to initialize the Analytics SDK:
Code:
HiAnalyticsInstance instance = HiAnalytics.getInstance (this);
3. Run the app and check whether data has been successfully reported based on the log content.
If the Analytics SDK fails to be integrated or report data:
An error code will be contained in the log, and some log content may be marked in red. Check whether related solutions are available by referring to Result Codes and Integration and Debugging.
If data is successfully reported, the key log content is as follows:
Code:
HiAnalyticsSDK: SendMission=> events PostRequest sendevent TYPE : oper, TAG : _openness_config_tag, resultCode: 200 ,reqID:xxx
In app debug mode, each time data is reported, the following log content is generated:
Code:
HiAnalyticsSDK: DeviceToolsKit=> debugMode enabled.
In app debug mode, if an event cannot be reported, the following log content is generated:
Code:
HiAnalyticsSDK: ReportRingback=> do not enable APIEvt in debug model
What can I do if the error message "client token request miss client id" is displayed during SDK initialization?​​[Error message]​
Code:
HiAnalyticsSDK: TokenAssignment=> SE-003|get token exception on the AGC! java.lang.IllegalArgumentException: client token request miss client id, please check whether the 'agconnect-services.json' is configured correctly
[Root cause]​
The Do not include key switch next to agconnect-services.json in the App information area on the Project settings page is toggled on. As a result, keys including the client key and API key are excluded from the configuration file, but APIs of the AppGallery Connect SDK have not been called to manually configure the key information.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
[Solution]​
If you have enabled Do not include key before downloading the agconnect-services.json file, call APIs of the AppGallery Connect SDK to manually configure the key information. For details, please refer to Setting Parameters Using the Configuration File.
3. What can I do if CE-001 or SE-001 is reported during SDK initialization?​
[Error message]​
Code:
HiAnalyticsSDK: jsonParses=> CE-001|Cannot find productId from agconnect-services.json
HiAnalyticsSDK: InitTask=> SE-001|_openness_config_tag instance config init failed!. param error config params is error
[Root cause]​
The parameters for integrating the SDK are incorrect due to the following reasons:
The agconnect-services.json file is saved in the incorrect path.
Content in the agconnect-services.json file is incomplete, or productId has been modified.
In the app-level build.gradle file, apply plugin: 'com.huawei.agconnect' has not been added, or id 'com.huawei.agconnect' has not been added to plugins.
Note: Add com.huawei.agconnect below com.android.application. Otherwise, an error will be reported.
[Solution]​
Place the agconnect-services.json file in the correct path.
Download the agconnect-services.json file from AppGallery Connect again and use it to replace the original one.
Add the com.huawei.agconnect configuration in the correct place.
You can check the configuration by referring to Integrating the SDK.
Learn more​
Official website of Analytics Kit
Development guide of Analytics Kit

Categories

Resources