設定

カスタム イベントを使用すると、サポートされている広告ネットワークでない広告ネットワーク用に、ウォーターフォール メディエーションを追加できます。そのためには、統合する広告ネットワークに対応するカスタム イベント アダプタを実装します。

GitHub リポジトリで、サンプル カスタム イベント プロジェクト全体を確認できます。

前提条件

カスタム イベントを作成するには、まず次のいずれかの広告フォーマットをアプリに統合しておく必要があります。

管理画面でカスタム イベントを作成する

カスタム イベントは、まず AdMobUI で作成する必要があります。手順については、 カスタム イベントを追加するをご覧ください。

次の情報を指定する必要があります。

Class Name

カスタム イベント アダプタを実装するクラスの完全修飾名(例: com.google.ads.mediation.sample.customevent.SampleCustomEvent)。すべてのカスタム イベント広告フォーマットに、単一のアダプタクラスを使用することをおすすめします。

ラベル

広告ソースを定義する一意の名前。

パラメータ

カスタム イベント アダプタに渡されるオプションの文字列引数。

アダプターを初期化する

Google Mobile Ads SDK が初期化されると、 initialize() は、UI 内でアプリ用に設定された、サポートされているすべてのサードパーティ アダプタとカスタム イベントで呼び出されます。 AdMob このメソッドを使用して、カスタム イベントに必要なサードパーティ SDK で必要な設定や初期化を行います。

Java

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

import com.google.android.gms.ads.AdFormat;
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.AdFormat
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()
  }
}

バージョン番号を報告する

すべてのカスタム イベントは、カスタム イベント アダプタ自体のバージョンと、カスタム イベントとやり取りするサードパーティ SDK のバージョンの両方を Google Mobile Ads 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)
  }
}

広告をリクエスト

広告をリクエストするには、それぞれの広告フォーマットの手順をご覧ください。