Huawei AGC-Push Notification AB Test Practical Guide

The Huawei AppGallery Connect service provides the AB test function, which can be used for Push notification or remote configuration, and create a control test test to compare the differences between different solutions. It can help product or operation colleagues to choose the best solution based on scientific data. .

The following is a practical tutorial for using the push notification AB test from scratch on the Huawei AGC platform. If there is something wrong, please give more guidance.

1. Integrated Push

First, before using the push notification AB test, you need to complete the integration of the Huawei Push service. This step is a prerequisite and a step that must be integrated. Some students' applications may use the integrated Push service provided by the three-party platform, such as the three-party platform such as Getuiyoumeng Jiguang. As long as the integration is completed correctly, the following steps are not required for this scenario.

The simplest steps to integrate Huawei Push on the Android platform are described below. You can also directly refer to the official documentation of Huawei Push for integration.

https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/android-app-quickstart-0000001071490422

1. Add the Maven repository address to the project-level build.gradle:

buildscript {
    repositories {
        maven { url 'https://developer.huawei.com/repo/'}
    }
    dependencies {
        classpath 'com.huawei.agconnect:agcp:1.5.2.300'
    }
}
allprojects {
    repositories {
        maven { url 'https://developer.huawei.com/repo/'}
    }
}

2. Add AGCP plugin and agc configuration file

1. Add the following agcp plugin to the application-level build.gradle

apply plugin: 'com.huawei.agconnect'

2. Under My Project -> Project Settings in the AGC console, download the agconnect-services.json file and download it to the app path of the project

cke_4923.png

3. Add SDK dependencies in application-level build.gradle

dependencies {
implementation 'com.huawei.hms:push:5.3.0.301'
implementation 'com.huawei.hms:hianalytics:5.3.1.300'
}

4. Apply for Push Token in the code

The following is a simple Android code. I just added a button to apply for Token in a completely new Android project.

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	findViewById(R.id.button).setOnClickListener(view -> {
		getToken();
	});

}

private void getToken() {
	// 创建一个新线程
	new Thread() {
		@Override
		public void run() {
			try {
				// 从agconnect-service.json文件中读取appId
				String appId = "your_APPId";
				// 输入token标识"HCM"
				String tokenScope = "HCM";
				String token = HmsInstanceId.getInstance(MainActivity.this).getToken(appId, tokenScope);
				Log.i(TAG, "get token: " + token);
				// 判断token是否为空
				if(!TextUtils.isEmpty(token)) {
					sendRegTokenToServer(token);
				}
			} catch (ApiException e) {
				Log.e(TAG, "get token failed, " + e);
			}
		}
	}.start();
}
private void sendRegTokenToServer(String token) {
	Log.i(TAG, "sending token to server. token:" + token);
}

5. Configure the signature file

The corresponding signature file needs to be configured in the build.gradle file of the application. If there is no signature file, you can manually generate one. The steps are as follows:

Click Build -> Select Generate Signed Bundle or APK -> Select APK -> Next select Create New to add a signature file.

cke_4924.png

After the signature file is generated, the configuration related to the configuration of the corresponding application-level build.gradle file is as follows:

android {
     signingConfigs {
         config {
             // xxx替换为您自己的签名文件
             keyAlias 'xxx'
             keyPassword 'xxxx'
             storeFile file('xxx.jks')
             storePassword 'xxxx'
         }
     }

     buildTypes {
         debug {
             signingConfig signingConfigs.config
         }
         release {
             signingConfig signingConfigs.config
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }
 }

6. Generate and configure SHA256 signature

6.1 Execute the keytool command

keytool -list -v -keystore <keystore-file>, where <keystore-file> is the full path of the application signing certificate, the command example is as follows

cke_4925.png

6.2 Configure SHA256 to AGC interface

cke_4926.png

2. Integrated Huawei Analysis

To generate the AB test report, you need to use the Huawei Analytics service. Therefore, you need to integrate the Huawei Analytics SDK in the code. Since the AB test events are automatically collected by Huawei Analytics, the integration steps of Huawei Analytics are very simple:

1. Add SDK dependencies in application-level build.gradle

dependencies {
implementation 'com.huawei.hms:hianalytics:5.3.1.300'
}

2. Initialize Huawei Analytics in OnCreate

HiAnalyticsTools.enableLog();
HiAnalyticsInstance instance = HiAnalytics.getInstance(this);

3. Run the App and get Push Token

The logs related to App running and getting Push Token are as follows

cke_4927.png

Fourth, create Push as a test.

In the AGC interface, select My Project, select Push Service on the project - select Add Push Notification;

https://developer.huawei.com/consumer/cn/service/josp/agc/index.html#/

Check a Push test as required, and push it to the designated device, and fill in the Token applied for in the previous step. After clicking submit, you can see the corresponding test results.

cke_4928.png

5. Create AB tests.

In the AGC interface, select My Project -> Select AB Test - select Create Notification Experiment in the upper right corner.

https://developer.huawei.com/consumer/cn/service/josp/agc/index.html#/

cke_4929.png

have to be aware of is:

  • Currently, the target user of the experiment can only select the audience group, but the audience group is from Huawei Analytics, and the data is calculated daily and generated every other day.

That is to say, the audience group selected today can only cover the users of yesterday. So be careful to test every other day.

  • After the created AB test, you can use the operation on the far right to select Commissioning to commission the Push effect. The aaid used for commissioning is obtained as follows
    public void getAAID() {
    	Task<AAIDResult> idResult = HmsInstanceId.getInstance(this).getAAID();
    	idResult.addOnSuccessListener(new OnSuccessListener<AAIDResult>() {
    		@Override
    		public void onSuccess(AAIDResult aaidResult) {
    			// 获取AAID方法成功
    			String aaid = aaidResult.getId();
    			Log.d(TAG, "getAAID successfully, aaid is " + aaid );
    		}
    	}).addOnFailureListener(new OnFailureListener() {
    		@Override
    		public void onFailure(Exception myException) {
    			// 获取AAID失败
    			Log.d(TAG, "getAAID failed, catch exceptio : " + myException);
    		}
    	});
    }
cke_4930.png

6. View the experimental report:

For the experiment that has been run, you can click the report in the operation bar on the right to view the corresponding AB test data report. The interface reference is as follows:  

cke_4931.png

7. Reference documents:

1. Huawei AGC AB test operation document

https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-abtest-introduction-0000001058210679

2. Huawei Push SDK Development Guide:

https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides-V5/android-app-quickstart-0000001071490422-V5

3. Huawei Analytics SDK Development Guide:

https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/android-dev-process-0000001050163813

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4478396/blog/5512597