2

Why do conversion tracking

There is an old saying in the advertising industry. I know that half of my advertising expenses are wasted, but I don't know how it is wasted. So for advertisers, ad tracking is very important. When you spend a lot of budget on advertising, what is the effect? How to adjust and optimize the delivery strategy based on the data of each ad delivery depends on ad tracking.

But the reality is that there is a natural separation between the advertising platform and the advertiser's data. The advertising platform can collect installation events, but the conversion events such as payment and activation in the app cannot be collected by the platform, and the real conversion rate cannot be analyzed. Advertisers can easily collect the actual conversion situation, but it cannot be associated with the advertising task, which affects the optimization of subsequent delivery. Through conversion tracking, the conversion event on the advertiser side can be associated with the delivery task on the advertising platform side, so as to provide data support for the analysis of the delivery effect.

What is conversion tracking

Conversion tracking is a product that reports the conversion behaviors (OAID, timestamp, conversion behavior, behavior parameters) most concerned by advertisers to the advertising platform through API, SDK, etc. Based on conversion tracking, advertisers can track advertising effects in detail, monitor the traffic and corresponding conversion effects brought by different platforms and different forms of advertising, and provide accurate data for the continuous optimization of advertising.

In order to better help advertisers to promote applications on Huawei devices, Huawei Advertising Service (HUAWEI Ads Kit) also provides conversion tracking capabilities to facilitate advertisers to track advertising conversion channels and analyze conversion effects.

How Huawei Advertising Service Conversion Tracking Parameter Capability Works

1. Advertiser App integrates advertising services to obtain conversion tracking parameter capabilities and puts it on the Huawei AppGallery.
2. Advertisers place App download ads on Huawei's advertising platform (Ad Network) and set conversion tracking parameters. 3. Media App (Media App) requests and displays advertisements placed by advertisers.
4. The user clicks on the advertisement placed by the advertiser on the media App, and the user can select and download and install the advertiser App.
5. Huawei AppGallery writes conversion tracking parameters into advertising services.
6. When the user activates the advertiser App on the end side, the App obtains the conversion tracking parameters from the advertising service.
7. The advertiser App reports the activation event to the Third-party tracking platform, which can use conversion tracking parameters to analyze the conversion effect of the App.

Development steps

1. Integrated conversion tracking parameter opening capability (SDK method)
The SDK method refers to advertisers accessing open capabilities through the SDK provided by Huawei Advertising Services to obtain App conversion tracking parameters

integrated SDK

1. Configure the Maven warehouse address of HUAWEI Ads SDK
Open the Android Studio project-level "build.gradle" file, and configure the Maven repository address of the SDK in "allprojects> repositories".

allprojects { 
        repositories { 
                google() 
                jcenter() 
                maven { url 'https://developer.huawei.com/repo/' } 
        } 
}

2. Configuration dependencies
Open the "build.gradle" file under the subproject "app", add SDK dependencies in dependencies, and replace {version} with the actual HUAWEI Ads SDK version number. Please refer to version update instructions .

dependencies { 
        implementation 'com.huawei.hms:ads-installreferrer:{version}' 
}

3. Synchronize modified files

4. It needs to be configured before PK not to confuse the HUAWEI Ads SDK to avoid functional abnormalities.
Open the "app/proguard-rules.pro" obfuscation configuration file in the application-level root directory of the Android project, add the following two lines of code, and add the obfuscation configuration that excludes the HUAWEI Ads SDK.

allprojects { 
        repositories { 
                google() 
                jcenter() 
                maven { url 'https://developer.huawei.com/repo/' } 
        } 
}

Create conversion tracking parameter status listener
1. The two methods onInstallReferrerSetupFinished and onInstallReferrerServiceDisconnected that implement the InstallReferrerStateListener listener interface are as follows:

/** 
* 创建监听 
*/ 
private InstallReferrerStateListener installReferrerStateListener = new InstallReferrerStateListener() { 
 @Override 
 public void onInstallReferrerSetupFinished(int responseCode) { 
     switch (responseCode) { 
         case InstallReferrerClient.InstallReferrerResponse.OK: 
             Log.i(TAG, "connect ads kit ok"); 
             get(); 
             break; 
         case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED: 
             // 服务不支持,请下载并安装最新版本的HMS Core(APK) 
             Log.i(TAG, "FEATURE_NOT_SUPPORTED"); 
             break; 
         case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE: 
             // 服务不可用,请将HMS Core(APK)版本升级到2.6.5及以上 
             Log.i(TAG, "SERVICE_UNAVAILABLE"); 
             break; 
         default: 
             Log.i(TAG, "responseCode: " + responseCode); 
             break; 
     } 
 } 
 
 @Override 
 public void onInstallReferrerServiceDisconnected() { 
     Log.i(TAG, "onInstallReferrerServiceDisconnected"); 
 } 
};

2. In the callback of successful connection, call the getInstallReferrer method to obtain conversion tracking parameters.

/** 
* 获取转化跟踪参数 
*/ 
private void get() { 
 if (null != mReferrerClient) { 
     try { 
         // 获取referrerDetails实例,不要在主线程中调用此方法 
         ReferrerDetails referrerDetails = mReferrerClient.getInstallReferrer(); 
         if (null != referrerDetails && null != mCallback) { 
             // 更新数据 
             mCallback.onSuccess(referrerDetails.getInstallReferrer(), 
                     referrerDetails.getReferrerClickTimestampMillisecond(), 
                     referrerDetails.getInstallBeginTimestampMillisecond()); 
         } 
     } catch (RemoteException e) { 
         Log.i(TAG, "getInstallReferrer RemoteException: " + e.getMessage()); 
     } catch (IOException e) { 
         Log.i(TAG, "getInstallReferrer IOException: " + e.getMessage()); 
     } finally { 
         disconnect(); 
     } 
 } 
}

Create InstallReferrerClient instance
Configure and create an InstallReferrerClient instance through the builder.
1. Call InstallReferrerClient.newBuilder to create a Builder instance.
2. Call build to create an instance of InstallReferrerClient.

mReferrerClient = InstallReferrerClient.newBuilder(mContext).build();

Connect to the conversion tracking parameter service
Establish a connection with the conversion tracking parameter service.
1. Set the listener of startConnection to the created InstallReferrerStateListener listener.
2. Call the startConnection method in the child thread to connect to the service.

mReferrerClient.startConnection(installReferrerStateListener);

2. Integrated conversion tracking parameter opening capability (AIDL method)

In addition to accessing the SDK, advertisers can also directly call the AIDL interface of Huawei advertising services to obtain conversion tracking parameters on Huawei devices. The two methods to obtain conversion tracking parameters for the same device are the same.

Added AIDL interface file
Add an "IPPSChannelInfoService.aidl" interface file to the project "app/src/main/aidl/com/huawei/android/hms/ppskit/" path, the package name is "com.huawei.android.hms.ppskit", Then copy the following content to the interface file.

// IPPSRemoteService.aidl 
 package com.huawei.android.hms.ppskit; 
 /* 
  * 注意:不要修改AIDL文件的方法顺序 
  */ 
 interface IPPSChannelInfoService { 
 
     String getChannelInfo(); 
 }

creates a class that implements the ServiceConnection interface

1. Implement the onServiceConnected method of ServiceConnection.
2. Call IPPSChannelInfoService.Stub.asInterface method to obtain IPPSChannelInfoService.
3. Call the getChannelInfo method to obtain conversion tracking parameters.

private final class InstallReferrerServiceConnection implements ServiceConnection { 
 
     private InstallReferrerServiceConnection() { 
     } 
 
     @Override 
     public void onServiceConnected(ComponentName componentName, IBinder iBinder) { 
         Log.i(TAG, "onServiceConnected"); 
         mService = IPPSChannelInfoService.Stub.asInterface(iBinder); 
         if (null != mService) { 
             try { 
                 // 获取渠道信息(Json格式) 
                 String channelJson = mService.getChannelInfo(); 
                 Log.i(TAG, "channelJson: " + channelJson); 
                 // 解析 
                 JSONObject jsonObject = new JSONObject(channelJson); 
                 // 获取转化跟踪参数 
                 String installReferrer = jsonObject.optString("channelInfo"); 
                 long clickTimestamp = jsonObject.optLong("clickTimestamp", 0); 
                 long installTimestamp = jsonObject.optLong("installTimestamp", 0); 
                 if (null != mCallback) { 
                     // 更新数据 
                     mCallback.onSuccess(installReferrer, clickTimestamp, installTimestamp); 
                 } else { 
                     mCallback.onFail("install referrer is empty"); 
                 } 
             } catch (RemoteException e) { 
                 Log.e(TAG, "getChannelInfo RemoteException"); 
                 mCallback.onFail(e.getMessage()); 
             } catch (Exception e) { 
                 Log.e(TAG, "getChannelInfo Exception"); 
                 mCallback.onFail(e.getMessage()); 
             } finally { 
                 unbindService(); 
             } 
         } 
     } 
 
     @Override 
     public void onServiceDisconnected(ComponentName componentName) { 
         Log.i(TAG, "onServiceDisconnected"); 
         mService = null; 
     } 
 }

AIDL service connected to conversion tracking parameters
1. Create an instance of InstallReferrerServiceConnection.
2. Create an Intent, the Action is "com.huawei.android.hms.CHANNEL_SERVICE".
3. Set the package name of the Intent to "com.huawei.hwid".
4. Call bindService to connect the AIDL service with conversion tracking parameters

private boolean bindService() { 
     Log.i(TAG, "bindService"); 
     if (null == mContext) { 
         Log.e(TAG, "context is null"); 
         return false; 
     } 
     mServiceConnection = new InstallReferrerServiceConnection(); 
     Intent intent = new Intent(Constants.SERVICE_ACTION); 
     intent.setPackage(Constants.SERVICE_PACKAGE_NAME); 
     // 绑定服务 
     boolean result = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); 
     Log.i(TAG, "bindService result: " + result); 
     return result; 
 }

Disconnect AIDL service for conversion tracking parameters
After using the AIDL interface, you should actively disconnect the service connection.

private void unbindService() { 
     Log.i(TAG, "unbindService"); 
     if (null == mContext) {     
         Log.e(TAG, "context is null");     
         return; 
     } 
     if (null != mServiceConnection) { 
         // 解绑服务 
         mContext.unbindService(mServiceConnection); 
         mService = null; 
         mContext = null; 
         mCallback = null; 
     } 
 }

Third, access to single machine test
After completing the above-mentioned completion of the business code for obtaining the conversion tracking parameters, it can be compiled. After the compilation is completed, an APK is generated to install and run. Provides related Demo , which can generate conversion tracking parameters on the end side for testing.

Modify the App to test conversion tracking parameters.
SDK method: Set to test mode when creating InstallReferrerClient, call setTest(true), the sample code is as follows:

mReferrerClient = InstallReferrerClient.newBuilder(mContext).setTest(true).build(); 
mReferrerClient.startConnection(installReferrerStateListener);

AIDL method: Set the package name of the bound AIDL service to "com.huawei.pps.hms.test" during testing. The sample code is as follows:

mServiceConnection = new InstallReferrerServiceConnection(); 
Intent intent = new Intent(Constants.SERVICE_ACTION); 
intent.setPackage(Constants.TEST_SERVICE_PACKAGE_NAME); 
boolean result = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); 
Log.i(TAG, "bindService result: " + result);

Compile the project to generate an APK file, and install the APK file to the device. Run the App, and the following page is displayed.

Click "Write test conversion tracking parameters", the interface will jump to the page shown in the figure below, enter the App package name (see "AndroidManifest.xml") and conversion tracking parameters, and save them.

Fourth, product joint debugging

After obtaining the conversion tracking parameters, you need to log in to the Huawei advertising platform to associate the advertising tracking parameters with the promotion task
1. After the advertiser App integrates conversion tracking parameters, it will be put on the Huawei App Market.
2. When creating a promotion task on the Huawei advertising platform, set the conversion tracking parameters, as shown in the following figure:

3. Read conversion tracking parameters. When the advertiser App is activated, it will read the conversion tracking parameters and report the information to the developer's analysis platform.

For more details

Visit the official website of Huawei Advertising Service
Huawei Advertising Service Development Guidance Document
Huawei advertising service open source warehouse address: GitHub , Gitee
Huawei HMS Core official forum
To solve integration problems, please go to Stack Overflow

and learn about the latest technology of HMS Core for the first time~


HarmonyOS_SDK
596 声望11.7k 粉丝

HarmonyOS SDK通过将HarmonyOS系统级能力对外开放,支撑开发者高效打造更纯净、更智能、更精致、更易用的鸿蒙原生应用,和开发者共同成长。