Introduction:
In this section let us see what are basic issues faced by developers while integrating HMS analytics kits. Huawei developer sites provide excellent guides to integrate easy way. But if you still end up hitting road blocks please refer below blog, which will help you fix those.
What are the tags to check when analysing analytics kit logs? I have gathered below tags and information from analytics logs, this will help you have better idea about how logic flows in the analytics kit.
Tags/Strings you can search for in the logs:
HiAnalyticsSDK
AAID Processor
Token Processor
regHMSEvent()
{
"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"
}
How to take android logs?
In general, taking android logs you will get lot of information regarding the other applications and system infos. To filter analytics sdk specific logs, search for HiAnalyticsSDK tag in android logs. This can narrow down our search a lot.
Code:
adb logcat | findstr "HiAnalyticsSDK"
Are you missing agconnect-services.json?
If you forgot to add agconnect-services.json in the application you will facing this above error. So add your agconnect-services from app-gallery connect. There you go that is straight forward.
Code:
java.lang.RuntimeException: Unable to get provider com.huawei.agconnect.core.provider.AGConnectInitializeProvider: java.security.InvalidParameterException: url is null
Have you enabled the analytics kit in AG-Connect?
If you have forgot to enable Analytics APIs in AG-Connect or if you have setHiAnalyticsInstance.setAnalyticsEnabled(false) the you will have this in your logs.
Code:
HiAnalyticsKit: HiAnalyticsLoginService=> service onBind
HiAnalyticsSDK: HAServiceConnection=> onServiceConnected
HiAnalyticsSDK: HAServiceConnection=> onServiceDisconnected
Enable the Analytics using the API HiAnalyticsInstance.setAnalyticsEnabled(true) and check the logs.and Select any menu under HUAWEI Analytics and click Enable Analytics service. (Only users with the management permission can perform this operation.) Now it will be fine.
Code:
HiAnalyticsKit: HiAnalyticsLoginService=> service onBind
HiAnalyticsSDK: HAServiceConnection=> onServiceConnected
HiAnalyticsSDK: HAServiceConnection=> Upload info is correct
HiAnalyticsKit: HiAnalyticsUtil=> http header pkgName: com.huawei.hms.analytics
HiAnalyticsKit: HiAnalyticsUtil=> analytics sdk start init
Are you facing SHA-ID signature mismatch?
Huawei developer’s portal has easy way to add SHA-ID in your application and AG-Connect. If you somehow messed it up or when the sha-id in AG-Connect and application mismatch, then we will have this error in the logs.
Code:
HiAnalyticsSDK: TokenProcessor=> SE-003|Failed to obtain token from agconnect sdk, token is empty
HiAnalyticsSDK: TokenProcessor=> success: 0
HiAnalyticsSDK: TokenProcessor=> SE-003|Failed to obtain token from agconnect sdk, token is empty
HiAnalyticsSDK: TokenProcessor=> success: 0
HiAnalyticsSDK: EventReportTask=> agc token is empty, stop event report.
Recreate and do the generate signature again to fix the issue
Code:
HiAnalyticsSDK: TokenProcessor=> start get token from agc
HiAnalyticsSDK: AAIDProcessor=> Task<String>.addOnSuccessListener onSuccess!
HiAnalyticsSDK: TokenProcessor=> success: 172800
Is your events not registered?
If you haven't registered the events regHMSEvent() in the code you will face below logs.
Code:
HiAnalyticsSDK AAIDProcessor=> begin sync aaid from opendevice sdk
HiAnalyticsSDK AAIDProcessor=> get aaid success
HiAnalyticsSDK TokenProcessor=> start get token from agc
HiAnalyticsSDK EventRecordTask=> Begin to run EventRecordTask...
HiAnalyticsSDK TokenProcessor=> success: 172800
HiAnalyticsSDK EventRecordTask=> Begin to run EventRecordTask...
HiAnalyticsSDK EventRecordTask=> Begin to run EventRecordTask...
Register your events to fix the issue using regHMSEvent()
Code:
HiAnalyticsSDK AAIDProcessor=> begin sync aaid from opendevice sdk
HiAnalyticsSDK AAIDProcessor=> get aaid success
HiAnalyticsSDK TokenProcessor=> start get token from agc
HiAnalyticsSDK: HiAnalyticsInstanceManager=> regHmsSvcEvent is execute
HiAnalyticsSDK EventRecordTask=> Begin to run EventRecordTask...
HiAnalyticsSDK TokenProcessor=> success: 172800
More details, you can visit https://forums.developer.huawei.com/forumPortal/en/topic/0204400503644150106
How much time it takes to reflect the event on dashboard?
Related
HUAWEI Analytics Kit is based on the event analytics data model.
The analytics data model uses the Event-Param-User model to record data, describes events using parameters, and describes the characteristics of users.
{
"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"
}
HUAWEI Analytics Kit collects the AAID that is allocated by the HMS Instance ID to each app instance installed on the device. The AAID is used for connecting various HMS Core services, such as HUAWEI Push Kit, HUAWEI Analytics Kit, and Remote Configuration.
The AAID will be reset in the following scenarios:
The user uninstalls or reinstalls the app.
The user restores the device to its factory settings.
The user clears the app data.
The app calls the clearCachedData API.
Procedure
1. Initialize the HMS Core Analytics SDK by calling the getInstance API.
Code:
HiAnalyticsInstance instance = HiAnalytics.getInstance(context);
2. Record defined events using the onEvent API. For definitions of the events, please refer to Event Description.
3. Call APIs of HUAWEI Analytics Kit to implement the corresponding functions. For details, please refer to API Reference. For example, call the setUserProfile API to set user attributes.
Sample Code
1. After the agconnect-services.json file is imported successfully, initialize HUAWEI Analytics Kit in the onCreate method of the first activity to obtain a HiAnalyticsInstance instance. If the agconnect-services.json file is incorrect, data cannot be collected at specified trigger points.
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Enable SDK log recording.
HiAnalyticsTools.enableLog();
HiAnalyticsInstance instance = HiAnalytics.getInstance(this);
// Or use the context for initialization.
// Context context = this.getApplicationContext();
// HiAnalyticsInstance instance = HiAnalytics.getInstance(context);
// instance.setUserProfile("userKey","value");
}
2. Insert trigger points in proper positions of the code.
Code:
//Customize trigger points and add trigger points in the proper position of the code.
Bundle bundle = new Bundle();
bundle.putString("exam_difficulty","high");
bundle.putString("exam_level","1-1");
bundle.putString("exam_time","20190520-08");
instance.onEvent("begin_examination", bundle);
//Add trigger points for predefined events.
Bundle bundle_pre = new Bundle();
bundle_pre.putString(PRODUCTID, "item_ID");
bundle_pre.putString(PRODUCTNAME, "name");
bundle_pre.putString(CATEGORY, "category");
bundle_pre.putLong(QUANTITY, 100L);
bundle_pre.putDouble(PRICE, 10.01);
bundle_pre.putDouble(REVENUE, 10);
bundle_pre.putString(CURRNAME, "currency");
bundle_pre.putString(PLACEID, "location_ID");
instance.onEvent(ADDPRODUCT2WISHLIST, bundle_pre);
Using the Debug Mode
During the development, you can enable the debug mode to view the event records in real time, observe the results, and adjust the event tracing scheme.
Enabling/Disabling the Debug Mode
Run the following command on an Android device to enable the debug mode:
Code:
adb shell setprop debug.huawei.hms.analytics.app package_name
After the debug mode is enabled, all events will be reported in real time.
Run the following command to disable the debug mode:
Code:
adb shell setprop debug.huawei.hms.analytics.app .none.
You can go to HUAWEI Analytics > Management > App Debugging to view the reported data, as shown in the following figure.
For details about how to view the analysis data, please refer to App Debugging.
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.
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
{
"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"
}
Introduction
In this article, we will learn how to integrate Huawei Analytics kit in Android application KnowMyBoard. Account Kit provides seamless login functionality to the app with large user base.
Huawei Analytics kit provides very easy and convenient way to add custom events, custom events can be used to meet personalized analysis requirements that cannot be met by automatically collected events or predefined events. Analytics Kit allows you to customize events and extend event parameters, or add personalized parameters for predefined events.
Supported Devices
Restrictions
Number of events: A maximum of 500 events are supported.
Number of event parameters: You can register a maximum of 25 parameters for each event, and a maximum of 500 event parameters for each project.
Development Overview
You need to install Android Studio IDE and I assume that you have prior knowledge of Android application development.
Hardware Requirements
A computer (desktop or laptop) running Windows 10.
Android phone (with the USB cable), which is used for debugging.
Software Requirements
Java JDK 1.8 or later.
Android Studio software or Visual Studio or Code installed.
HMS Core (APK) 4.X or later
Integration steps
Step 1. Huawei developer account and complete identity verification in Huawei developer website, refer to register Huawei ID.
Step 2. Create project in AppGallery Connect
Step 3. Adding HMS Core SDK
Let's start coding
How to Add Custom Event in AGC?
Login to AppGallery Connect Console, select projects and choose your project and navigate to Events
How to initialize Analytics Kit?
[/B]
public class MyApplication extends Application {
public static Activity myactivity;
static HiAnalyticsInstance instanceAnalytics;
@Override
public void onCreate() {
super.onCreate();
MLApplication.initialize(this);
//initialize Analytics Kit
instanceAnalytics = HiAnalytics.getInstance(this);
MLApplication.getInstance().setApiKey(Constants.API_KEY);
MapsInitializer.setApiKey(Constants.API_KEY);
}
public static HiAnalyticsInstance getAnalyticsInstance(){
return instanceAnalytics;
}
public static void setActivity(Activity activity) {
myactivity= activity;
}
public static Activity getActivity() {
return myactivity;
}
}
[B]
How to send Custom Events?
[/B][/B]
private void sendEvent(String eventName,String eventType) {
Bundle bundle = new Bundle();
bundle.putString(eventType,eventType);
bundle.putString( "event_time", getTime());
MyApplication.getAnalyticsInstance().onEvent(eventName, bundle);
}
[B][B]
Result
Tricks and Tips
Makes sure that agconnect-services.json file added.
Make sure required dependencies are added
Make sure that service is enabled in AGC
Enable data binding in gradle.build file
Enable debug mode to see events details in get App debugging hit this command in terminal
adb shell setprop debug.huawei.hms.analytics.app pkg_name
Conclusion
Finally, we have learnt how to integrate Huawei Analytics kit in Android application KnowMyBoard. You can check the desired result in the result section. You can also go through previous article part-5 here. Hoping Huawei Analytics kit capabilities are helpful to you as well, like this sample, you can make use as per your requirement.
Thank you so much for reading. I hope this article helps you to understand the integration of Huawei Analytics kit in Android application KnowMyBoard.
Reference
Huawei Analytics Kit — Training video
Checkout in forum
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