設定

使用自訂事件,即可為未放送廣告的廣告聯播網新增刊登序列中介服務 支援的廣告聯播網。方法是為要整合的廣告聯播網導入自訂事件轉接程式。

必要條件

您必須先整合下列其中一個 導入下列廣告格式:

在使用者介面中建立自訂事件

您必須先在 Ad Manager 中建立自訂事件 第一種是使用無代碼解決方案 AutoML 透過使用者介面建立機器學習模型相關操作說明請參閱: 建立及管理收益 群組

您必須提供以下資訊:

類別名稱

實作自訂事件轉接器的類別完整名稱,例如 com.google.ads.mediation.sample.customevent.SampleCustomEvent。最佳 做法是在所有自訂事件廣告都使用單一轉接程式類別 格式。

標籤

定義廣告來源的專屬名稱。

參數

傳送至自訂事件轉接程式的選用字串引數。

初始化轉接程式

Google Mobile Ads SDK 初始化時 initialize() 會在所有支援的第三方轉接程式和自訂事件上叫用 Ad Manager 使用者介面的顯示設定使用這個方法,針對自訂事件的必要第三方 SDK 執行任何必要的設定或初始化作業。

Java

package com.google.ads.mediation.sample.customevent;

import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.InitializationCompleteCallback;
import com.google.android.gms.ads.mediation.MediationConfiguration;

public class SampleAdNetworkCustomEvent extends Adapter {
  private static final String SAMPLE_AD_UNIT_KEY = "parameter";

  @Override
  public void initialize(Context context,
      InitializationCompleteCallback initializationCompleteCallback,
      List<MediationConfiguration> mediationConfigurations) {
    // This is where you will initialize the SDK that this custom
    // event is built for. Upon finishing the SDK initialization,
    // call the completion handler with success.
    initializationCompleteCallback.onInitializationSucceeded();
  }
}

Kotlin

package com.google.ads.mediation.sample.customevent

import com.google.android.gms.ads.mediation.Adapter
import com.google.android.gms.ads.mediation.InitializationCompleteCallback
import com.google.android.gms.ads.mediation.MediationConfiguration

class SampleCustomEvent : Adapter() {
  private val SAMPLE_AD_UNIT_KEY = "parameter"

  override fun initialize(
    context: Context,
    initializationCompleteCallback: InitializationCompleteCallback,
    mediationConfigurations: List<MediationConfiguration>
  ) {
    // This is where you will initialize the SDK that this custom
    // event is built for. Upon finishing the SDK initialization,
    // call the completion handler with success.
    initializationCompleteCallback.onInitializationSucceeded()
  }
}

回報版本號碼

所有自訂事件都必須向 Google Mobile Ads SDK 回報自訂事件轉接器本身的版本,以及自訂事件介面所連結的第三方 SDK 版本。版本會以 VersionInfo 物件回報:

Java

package com.google.ads.mediation.sample.customevent;

public class SampleCustomEvent extends Adapter {

  @Override
  public VersionInfo getVersionInfo() {
    String versionString = new VersionInfo(1, 2, 3);
    String[] splits = versionString.split("\\.");

    if (splits.length >= 4) {
      int major = Integer.parseInt(splits[0]);
      int minor = Integer.parseInt(splits[1]);
      int micro = Integer.parseInt(splits[2]) * 100 + Integer.parseInt(splits[3]);
      return new VersionInfo(major, minor, micro);
    }

    return new VersionInfo(0, 0, 0);
  }

  @Override
  public VersionInfo getSDKVersionInfo() {
    String versionString = SampleAdRequest.getSDKVersion();
    String[] splits = versionString.split("\\.");

    if (splits.length >= 3) {
      int major = Integer.parseInt(splits[0]);
      int minor = Integer.parseInt(splits[1]);
      int micro = Integer.parseInt(splits[2]);
      return new VersionInfo(major, minor, micro);
    }

    return new VersionInfo(0, 0, 0);
  }
}

Kotlin

package com.google.ads.mediation.sample.customevent

class SampleCustomEvent : Adapter() {
  override fun getVersionInfo(): VersionInfo {
    val versionString = VersionInfo(1,2,3).toString()
    val splits: List<String> = versionString.split("\\.")

    if (splits.count() >= 4) {
      val major = splits[0].toInt()
      val minor = splits[1].toInt()
      val micro = (splits[2].toInt() * 100) + splits[3].toInt()
      return VersionInfo(major, minor, micro)
    }

    return VersionInfo(0, 0, 0)
  }

  override fun getSDKVersionInfo(): VersionInfo {
    val versionString = VersionInfo(1,2,3).toString()
    val splits: List<String> = versionString.split("\\.")

    if (splits.count() >= 3) {
      val major = splits[0].toInt()
      val minor = splits[1].toInt()
      val micro = splits[2].toInt()
      return VersionInfo(major, minor, micro)
    }

    return VersionInfo(0, 0, 0)
  }
}

請求廣告

如要提出廣告要求,請參閱該廣告格式的操作說明: