開始使用安全信號

選取平台: HTML5 Android iOS tvOS

安全信號是從用戶端裝置收集並與特定出價方共用的編碼資料。本指南說明如何使用 IMA SDK 收集安全信號,並傳送至 Google Ad Manager。

安全信號 API 需要 Android 適用的 IMA SDK 3.29.0 以上版本。

如要選取信號和出價方,並啟用安全信號共用功能,請參閱「與出價方共用安全信號」。

使用第三方信號供應商

如要使用安全信號,您必須在應用程式中部署信號收集器轉接器類別,收集信號、編碼並傳遞至 IMA SDK。

請按照第三方供應商的操作說明設定帳戶、新增建構依附元件,並在應用程式中設定安全信號轉接程式。

Android 適用的 IMA SDK 會自動初始化每個安全信號轉接程式,您不需要對程式碼進行任何額外變更。

以下範例說明如何在專案中加入安全信號轉接程式:

傳送自訂資料

除了使用第三方信號供應商,您也可以收集、編碼及傳送信號和自訂資料。如要傳送含有自訂資料的安全信號,請務必先在 Ad Manager 中啟用自訂信號。

針對每項廣告請求,建立包含編碼自訂資料的 SecureSignals 物件 (以字串形式)。接著,呼叫 adsRequest.setSecureSignals() 方法,將 SecureSignals 物件加入廣告請求:

app/src/main/java/com/example/project name/MainActivity.java

...
private void requestAds(String adTagUrl) {
  // Create the ads request.
  AdsRequest request = sdkFactory.createAdsRequest();
  request.setAdTagUrl(adTagUrl);
  request.setContentProgressProvider(
      () -> {
        if (videoPlayer.getDuration() <= 0) {
          return VideoProgressUpdate.VIDEO_TIME_NOT_READY;
        }
        return new VideoProgressUpdate(
            videoPlayer.getCurrentPosition(), videoPlayer.getDuration());
      });
  
  SecureSignals signal = SecureSignals.create("My encoded signal string");
  request.setSecureSignals(signal);
  
  // Request the ad. After the ad is loaded, onAdsManagerLoaded() will be called.
  adsLoader.requestAds(request);
}
...