DEV Community

Josh
Josh

Posted on

Creating a Remote Configuration Experiment Using A/B Testing

A/B Testing allows you to run notifications experiments or Remote Configuration experiments, create A/B tests that engage with different audiences to compare your variants, and measure the aspects of your business that matter most to you, so that you can make informed decisions at all time.

Let’s take a look at how this process works in practice.

1. Integrating the Remote Configuration SDK and Setting the Default Parameter Value

a) Configure the Maven repository address in the project-level build.gradle file.

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/'}
    }
}
Enter fullscreen mode Exit fullscreen mode

b) Add the AppGallery Connect plugin and the JSON configuration file.
Add the AppGallery Connect plugin to the app-level build.gradle file.

apply plugin: 'com.huawei.agconnect'
Enter fullscreen mode Exit fullscreen mode

Sign in to AppGallery Connect, click My projects, click your project card, and go to Project settings > General information. Download the JSON configuration file and add it to the app directory of your project.

Image 7

C) Add the SDK dependency to the app-level build.gradle file.

dependencies {
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.5.2.300'
implementation 'com.huawei.hms:hianalytics:5.3.1.300'
}
Enter fullscreen mode Exit fullscreen mode

d) Set the default parameter value.
You can create a button for obtaining the updated parameter value from Remote Configuration.

Configure the default parameter value in the button, and apply the fetch method to obtain the updated parameter value from Remote Configuration. Set the following code:

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

 HiAnalyticsTools.enableLog();
 HiAnalyticsInstance instance = HiAnalytics.getInstance(this);
 getAAID();
 findViewById(R.id.button).setOnClickListener(view -> {
  getRemoteCongfig();
 });

}
public void getRemoteCongfig() {
 // Obtain the Remote Configuration instance.
 config = AGConnectConfig.getInstance();
 Map<String, Object> defaultValue = new HashMap<>();
 // Add a key-value pair.
 defaultValue.put("welcome_string", "this is a default welcome_slogan");
 config.applyDefault(defaultValue);

 config.fetch(10).addOnSuccessListener(configValues -> {
  config.apply(configValues);
  String newSlogan = config.getValueAsString("welcome_string");
  Log.i(TAG, "RemoteConfig Success: " + newSlogan);
 }).addOnFailureListener(e1 ->
   Log.e(TAG, "getRemoteConfig failed: " + e1.getMessage())
 );
}
Enter fullscreen mode Exit fullscreen mode

2. Integrating Analytics Kit

To generate reports for A/B tests, HUAWEI Analytics will need to be enabled, since it automatically captures A/B Testing events.

a) Add the SDK dependency to the app-level build.gradle file.

dependencies {
implementation 'com.huawei.hms:hianalytics:5.3.1.300'
}
Enter fullscreen mode Exit fullscreen mode

b) Initialize HUAWEI Analytics in onCreate.

HiAnalyticsTools.enableLog();
HiAnalyticsInstance instance = HiAnalytics.getInstance(this);
Enter fullscreen mode Exit fullscreen mode

3. Setting the Parameter Value in Remote Configuration

Sign in to AppGallery Connect, click My projects, click the project card, and select your app. Go to Grow > Remote Configuration, and click New parameter.

Image 8

Note: Make sure that the parameter name is the same as that of the default parameter.

Save the parameter settings and click Release.

4. Creating a Remote Configuration Experiment

In AppGallery Connect, click My projects, click the project card, and select your app. Go to Grow > A/B Testing. On the A/B Testing page, select Remote configuration from the New experiment drop-down list.

Configure a higher user percentage for Target users, and skip Activation event.

Set Conditions to Language, and select the languages as needed.

Image 1

Configure Parameter for Treatment & control groups as follows.

Image 2

Set Indicators to track, for example, to Click-through rate. Click Save to save all configurations.

5. Starting Your Experiment and Fetching the Parameter Value from Remote Configuration

a) Click Start under the Operation column of the record to run the experiment in AppGallery Connect.

Image 3

b) Run your app, and click the button to fetch the parameter value from Remote Configuration.
The log is as follows:

Image 4

Pay attention to the following:

  • You can click Test under the Operation column of the experiment record. The anonymous application identifier (AAID) of the test device can be obtained as follows:
public void getAAID() {
 Task<AAIDResult> idResult = HmsInstanceId.getInstance(this).getAAID();
 idResult.addOnSuccessListener(new OnSuccessListener<AAIDResult>() {
  @Override
  public void onSuccess(AAIDResult aaidResult) {
   // Obtained the AAID successfully.
   String aaid = aaidResult.getId();
   Log.d(TAG, "getAAID successfully, aaid is " + aaid );
  }
 }).addOnFailureListener(new OnFailureListener() {
  @Override
  public void onFailure(Exception myException) {
   // Failed to obtain the AAID.
   Log.d(TAG, "getAAID failed, catch exceptio : " + myException);
  }
 });
}
Enter fullscreen mode Exit fullscreen mode

Image 5

6. Viewing the Experiment Report

Click View report under the Operation column of a record to view the details for the experiment.

Image 6

References

Top comments (0)