Integrating Huawei Analytics kit using Flutter (Cross Platform)

Huawei Analytics kit offers you a range of analytics models that help you to analyze the users’ behavior with predefined and custom events, you can gain a deeper insight into your users, products and content.it helps you gain insight into how users behaves on different platforms based on the user behavior events and user attributes reported by through apps.

sujith E
Huawei Developers
4 min readDec 18, 2020

--

Huawei Analytics kit, our one-stop analytics platform provides developers with intelligent, convenient and powerful analytics capabilities, using this we can optimize apps performance and identify marketing channels.

Use Cases

1. Analyze user behaviours’ using both predefined and custom events.

2. Use audience segmentation to tailor your marketing activities to your users’ behaviours’ and preferences.

3. Use dashboards and analytics to measure your marketing activities and identify areas to improve.

Automatically collected events are collected from the moment you enable the Analytics. Event IDs are already reserved by HUAWEI Analytics Kit and cannot be reused.

Predefined events include their own Event IDs which are predefined by the HMS Core Analytics SDK based on common application scenarios

Custom events are the events that you can create based on your own requirements.

Flutter setup

Refer this URL to setup Flutter.

Software Requirements

1. Android Studio 3.X

2. JDK 1.8 and later

3. SDK Platform 19 and later

4. Gradle 4.6 and later

Steps to integrate service

1. We need to register as a developer account in AppGallery Connect

2. Create an app by referring to Creating a Project and Creating an App in the Project

3. Set the data storage location based on current location.

4. Enabling Required Services: Analytics Kit

5. Generating a Signing Certificate Fingerprint.

6. Configuring the Signing Certificate Fingerprint.

7. Get your agconnect-services.json file to the app root directory

Development Process

Create Application in Android Studio.

1. Create Flutter project.

2. App level gradle dependencies. Choose inside project Android > app > build.gradle

apply plugin: 'com.android.application'

apply plugin: 'com.huawei.agconnect'

Root level gradle dependencies

maven {url 'https://developer.huawei.com/repo/'}

classpath 'com.huawei.agconnect:agcp:1.4.1.300'

App level gradle dependencies

implementation 'com.huawei.hms:hianalytics:5.0.3.300'

Add the below permissions in Android Manifest file.

<manifest xlmns:android...>

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="com.huawei.appmarket.service.commondata.permission.GET_COMMON_DATA" />

<application>

</manifest>

3. Add HMS Analytics kit plugin download using below URL.

https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Library-V1/flutter-sdk-download-0000001050181641-V1

4. On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies to download the package from pub.dev. Or if you downloaded the package from the HUAWEI Developer website, specify the library path on your local device. For both ways, after running pub get command, the plugin will be ready to use.

description: A new Flutter application.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:

sdk: ">=2.7.0 <3.0.0"

dependencies:

flutter:

sdk: flutter

huawei_account:

path: ../huawei_account/

huawei_analytics:

path: ../huawei_analytics/

cupertino_icons: ^1.0.0

image_picker: ^0.6.7+4

path_provider: ^1.6.11

dev_dependencies:

flutter_test:

sdk: flutter

flutter:

uses-material-design: true

Define Analytics kit:

Before sending events we have to enable logs. Once we enable log we can collect events on AppGallery Connect.

HMSAnalytics _hmsAnalytics = new HMSAnalytics();

@override

void initState() {

_enableLog();

super.initState();

}

Future<void> _enableLog() async {

await _hmsAnalytics.enableLog();

}

Create Custom Events:Custom events can be used to track personalized analysis requirement.

try {

final AuthHuaweiId accountInfo = await HmsAccount.signIn(authParamHelper);

//Custom Event

String name = "USER";

dynamic value = {'Email': accountInfo.email};

await _hmsAnalytics.onEvent(name, value);

_showDialog(context, "Custom Event");

} on Exception catch (exception) {

print(exception.toString());

}

Predefined Events:Predefined events have been created by HMS Core based on common application scenarios.

//Predefined

void _predefinedEvent() async {

String name = HAEventType.UPDATEORDER;

dynamic value = {HAParamType.ORDERID: 06534797};

await _hmsAnalytics.onEvent(name, value);

}

AppGallery Connect:

Now we can check Analytics using AppGallery connect dashboard.

Choose My Projects > Huawei Analytics > Overview > Project overview.

Under Overview section, click Real-time we can track Real time events.

Under Management section click Events we can track predefined and custom events.

Result

Tips & Tricks

1. HUAWEI Analytics Kit identifies users and collects statistics on users by AAID.

2. HUAWEI Analytics Kit supports event management. For each event, maximum 25 parameters.

3. The AAID is reset if user uninstall or reinstall the app.

4. Default 24hrs it will take time to update the events to dashboard.

Conclusion

This article will help you to Integrate Huawei Analytics Kit to Flutter projects. Created some custom events, predefined events and monitor them into App Gallery Connect dashboard using custom events we can track user behaviours.

I explained to you how I Integrated the Analytics kit to Android application. For any questions, please feel free to contact me.

Thanks for reading!

Reference

Analytics kit Document

Refer the URL

--

--