Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Huawei DTM Kit Flutter Plugin - Demo


Contents


1. Introduction

This demo project is an example to demonstrate the features of the Huawei Flutter DTM Kit Plugin.


2. Installation

Before you get started, you must register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.

Creating a Project in AppGallery Connect

Creating an app in AppGallery Connect is required in order to communicate with Huawei services. To create an app, perform the following steps:

Step 1. Set an unique Application ID on the app level build gradle file located on example/android/app/build.gradle. You should also change the package names for the manifest files in the /example/android/app/src/ directory to match with the Application ID.

<!-- Other configurations ... -->
  defaultConfig {
    // Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). You may need to change the package name on AndroidManifest.xml and MainActivity.java respectively.
    // The Application ID here should match with the Package Name on the AppGalleryConnect.
      applicationId "<package_name>" //For ex: "com.example.mydtmproject"
      minSdkVersion 19
    <!-- Other configurations ... -->
}

Step 2. Sign in to AppGallery Connect and select My projects.

Step 3. Select your project from the project list or create a new one by clicking the Add Project button.

Step 4. Go to Project Setting > General information, and click Add app. If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click Add app.

Step 5. On the Add app page, enter the Application ID you've defined before as the Package Name here, then fill the necessary fields and click OK.

Configuring the Signing Certificate Fingerprint

  • A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core service through the HMS Core SDK. Before using HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in AppGallery Connect. Ensure that the JDK has been installed on your computer.

  • You can refer to 3rd and 4th steps of Generating a Signing Certificate codelab tutorial for the certificate generation. Perform the following steps after you have generated the certificate.

Step 1. Sign in to AppGallery Connect and select your project from My Projects. Then go to Project Setting > General information. In the App information field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA-256 certificate fingerprint.

Step 2. After completing the configuration, click OK to save the changes. (Check mark icon)

Step 3. Copy the signature file that you have generated to android/app directory.

Step 4. Enter the properties of the signature file to android/app/build.gradle file.

    android {
        /*
         * <Other configurations>
         */

        signingConfigs {
            config {
                storeFile file('<keystore_file>.jks')
                storePassword '<keystore_password>'
                keyAlias '<key_alias>'
                keyPassword '<key_password>'
            }
        }
    }

Enabling the Huawei Analytics Service

To use Huawei DTM, you need to enable Huawei Analytics in the following steps:

Step 1. Sign in to AppGallery Connect and select your project from My Projects. Then go to HUAWEI Analytics and click Enable Analytics service. You can also check Manage APIs tab on the Project Settings page for the enabled HMS services on your app.

Step 2. Go to Project Setting > General information page, under the App information field, click agconnect-services.json to download the configuration file.

Step 3. Copy the agconnect-services.json file to the example/android/app/ directory of the project.

Build & Run the project

Step 1. Run the following command to update package info.

[project_path]> flutter pub get

Step 2. Follow the configuration steps.

Step 3. Run the following command to start the demo app.

[project_path]> flutter run

3. Configuration

Operations on the Server

Overview

To access the DTM portal, perform the following steps:

Step 1. Sign in to AppGallery Connect and click My Projects.

Step 2. Find your app project, and click the desired app name.

Step 3. Go to Grow > Dynamic Tag Manager.

If you completed all the configurations, you must create Variables, Conditions and Tags as follows for the demo app to function properly.

Create Variable

A variable is a placeholder used in a condition or tag. For example, the App Name variable indicates the name of an Android app. DTM provides preset variables which can be used to configure most tags and conditions. You can also create your own custom variables. Currently, DTM provides 18 types of preset variables and 6 types of custom variables. Preset variable values can be obtained from the app without specifying any information. For a custom variable, you need to specify the mode to obtain its value.

Go to Variable section in Dynamic Tag Manager page.

Step 1. Create a custom variable.

  • Name : PantsPrice

  • Type : Function call

  • Class path : com.huawei.hms.flutter.dtm.interfaces.CustomVariable

  • Key: varName , Value: PantsPrice

    PantsPriceVariable

Step 2. Create a variable.

  • Name : PlatformName

  • Type : Event parameter

  • Event parameter key : platformName

    PlatformNameVariable

Step 3. Create a parameter (Event Name).

  • Press Configure button in Variable page. Then click Event Name and press OK.

    EventNameVariable

Create Condition

A condition is the prerequisite for triggering a tag and determines when the tag is executed. A tag must contain at least one trigger condition.

Go to Condition section in Dynamic Tag Manager page.

Step 1. Create a condition for PurchasePants tag.

  • Name : PurchasePants

  • Type : Custom

  • Trigger : Some events

    • Variable : Event Name
    • Operator : Equals
    • Value : PurchasePants

    PurchasePantsCondition

Step 2. Create a condition for SetPantsPrice tag.

  • Name : SetPantsPrice

  • Type : Custom

  • Trigger : Some events

    • Variable : Event Name
    • Operator : Equals
    • Value : SetPantsPrice

    SetPantsPriceCondition

Step 3. Create a condition for PurchaseShoes tag.

  • Name : PurchaseShoes

  • Type : Custom

  • Trigger : Some events

    • Variable : Event Name
    • Operator : Equals
    • Value : PurchaseShoes

    PurchaseShoesCondition

Create Tag

A tag is used in your app to track events. DTM supports the HUAWEI Analytics and custom function templates, as well as many third-party tag extension templates. With DTM, you do not need to add additional third-party tracking tags in your app. You can set parameters and trigger conditions for a tag in DTM, and release the configuration version to track events. You can also update and release tags for your app in DTM after you have released it, so you can adjust tag configurations in real time.

Go to Tag section in Dynamic Tag Manager page.

Step 1. Create a Custom Tag for CustomTag button.

  • Name : PurchaseShoes

  • Extension : Custom Function

  • Class path : com.huawei.hms.flutter.dtm.interfaces.CustomTag

  • Add

    • Key: itemName , Value: Shoes

    • Key: quantity , Value: 50

      PurchaseShoesTag

  • Condition : PurchaseShoes

Step 2. Create a Custom Tag to setCustomVariable.

  • Name : SetPantsPrice

  • Extension : Custom Function

  • Class path : com.huawei.hms.flutter.dtm.interfaces.CustomTag

  • Add

    • Key: discount , Value: 10
    • Key: price , Value: 100

    SetPantsPriceTag

  • Condition : SetPantsPrice

Step 3. Create a Tag that uses the PantsPrice customVariable value.

  • Name : PurchasePants

  • Extension : HUAWEI Analytics

  • Add

    • Key: price , Value: {{PantsPrice}}

    PurchasePantsTag

  • Condition : PurchasePants

Create Version

Go to Version section in Dynamic Tag Manager page. Press Create button in Version page. Enter a version name and click OK. Press the version which is created. Then click the Release button. After that click the Download button. DTM-****.json file will be downloaded.

Adding DTM-*****.json File To the Project

Go to android/app/src/main/assets directory in your project and add a new Directory named containers. Then copy the DTM-****.json file and paste it in containers directory.

Note

After each release, you need to replace the DTM-****.json with the new one.


4. Licensing and Terms

Huawei DTM Kit Flutter Plugin - Demo is licensed under Apache 2.0 license