使用場景
廣告主App開發(fā)者可通過廣告服務(wù)(HUAWEI Ads Kit)提供SDK,獲得App轉(zhuǎn)化跟蹤參數(shù),廣告主可基于轉(zhuǎn)化跟蹤參數(shù)進(jìn)行App推廣渠道分析,方便廣告主清楚掌握各渠道轉(zhuǎn)化效果分析。
注意事項(xiàng)
獲取轉(zhuǎn)化跟蹤參數(shù)前,確保App必須已經(jīng)集成ads-installreferrer SDK。
調(diào)用流程
開發(fā)步驟
1.創(chuàng)建轉(zhuǎn)化跟蹤參數(shù)狀態(tài)監(jiān)聽器。
實(shí)現(xiàn)InstallReferrerStateListener監(jiān)聽器接口的兩個(gè)方法onInstallReferrerSetupFinished和onInstallReferrerServiceDisconnected,示例代碼如下所示:
...
private static final String TAG = "InstallReferrerSdkActivity";
private InstallReferrerClient mReferrerClient;
/**
* 創(chuàng)建一個(gè)監(jiān)聽器
*/
private InstallReferrerStateListener installReferrerStateListener = new InstallReferrerStateListener() {
@Override
public void onInstallReferrerSetupFinished(int responseCode) {
switch (responseCode) {
case InstallReferrerClient.InstallReferrerResponse.OK:
Log.i(TAG, "connect ads kit ok");
// 獲取結(jié)果
try {
ReferrerDetails referrerDetails = mReferrerClient.getInstallReferrer();
} catch (RemoteException e) {
Log.i(TAG, "getInstallReferrer RemoteException: " + e.getMessage());
} catch (IOException e) {
Log.i(TAG, "getInstallReferrer IOException: " + e.getMessage());
}
break;
case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
Log.i(TAG, "FEATURE_NOT_SUPPORTED");
break;
case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
Log.i(TAG, "SERVICE_UNAVAILABLE");
break;
default:
Log.i(TAG, "responseCode: " + responseCode);
break;
}
}
@Override
public void onInstallReferrerServiceDisconnected() {
Log.i(TAG, "onInstallReferrerServiceDisconnected");
}
};
2.創(chuàng)建InstallReferrerClient實(shí)例。
a.調(diào)用InstallReferrerClient.newBuilder創(chuàng)建一個(gè)Builder實(shí)例。
b.調(diào)用build創(chuàng)建InstallReferrerClient實(shí)例。
mReferrerClient = InstallReferrerClient.newBuilder(InstallReferrerActivity.this).build();
3.連接轉(zhuǎn)化跟蹤參數(shù)服務(wù)。
a.創(chuàng)建一個(gè)子線程。
b.設(shè)置startConnection的監(jiān)聽器為已創(chuàng)建的InstallReferrerStateListener監(jiān)聽器。
private Thread connectThread = new Thread() {
@Override
public void run() {
connect();
}
}
/**
* 連接HMS Core服務(wù)
*/
private void connect() {
mReferrerClient = InstallReferrerClient.newBuilder(InstallReferrerActivity.this).build();
mReferrerClient.startConnection(installReferrerStateListener);
}
說明
建立與轉(zhuǎn)化跟蹤參數(shù)服務(wù)的連接,不要在主線程中調(diào)用該方法。