カスタム イベントを使用すると、メディエーションのサポート対象でない広告ネットワークもウォーターフォール メディエーションに組み込むことができます。これは、組み込みたい広告ネットワークに対応するカスタム イベント アダプタを実装することによって実現可能です。
前提条件
カスタム イベントを作成するには、あらかじめ次のいずれかの広告フォーマットをアプリに組み込んでおく必要があります。
UI でカスタム イベントを作成する
カスタム イベントはまずアド マネージャーの UI 内で作成する必要があります。収益グループを作成、管理するの手順をご覧ください。
以下を指定する必要があります。
- クラス名
- カスタム イベント アダプタを実装するクラスの完全修飾名です(例: - SampleCustomEvent。Swift で実装したクラスであれば- MediationExample.SampleCustomEventSwift)。- プロジェクトに複数のターゲットがある場合や、プロジェクト名がターゲット名と異なる場合は、ターゲット名が必要です。ターゲット名を指定する場合、 - appName_targetName.classNameのようになります。また、英数字以外の文字(ダッシュなど)は必ずアンダースコアに置き換えてください。例。
- ラベル
- 広告のソースを定義する一意の名前です。 
- パラメータ
- カスタム イベント アダプタに渡される文字列引数(任意使用)です。 
GADMediationAdapter を実装する
カスタム イベント作成の最初のステップは、GADMediationAdapter プロトコルの実装です。サンプル プロジェクトの SampleCustomEvent クラスをご覧ください。
このクラスは、Ad Manager からメッセージを受け取り、正しい広告フォーマットを作成する責任をデリゲートする役割を担います。
アダプタを初期化する
Google Mobile Ads SDK が初期化されると、Ad Manager の UI で該当アプリ用に設定されたすべてのサポート対象サードパーティ アダプタおよびカスタム イベントで、setUpWithConfiguration:completionHandler: が呼び出されます。カスタム イベントに必要なサードパーティ SDK でセットアップまたは初期化を行う際は、このメソッドを使用します。
Swift
import GoogleMobileAds
class SampleCustomEvent: NSObject, MediationAdapter {
  static func setUpWith(
    _ configuration: MediationServerConfiguration,
    completionHandler: @escaping GADMediationAdapterSetUpCompletionBlock
  ) {
    // 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.
    completionHandler(nil)
  }
}
Objective-C
#import "SampleCustomEvent.h"
@implementation SampleCustomEvent
+ (void)setUpWithConfiguration:(nonnull GADMediationServerConfiguration *)configuration
             completionHandler:(nonnull GADMediationAdapterSetUpCompletionBlock)completionHandler {
  // This is where you initialize the SDK that this custom event is built
  // for. Upon finishing the SDK initialization, call the completion handler
  // with success.
  completionHandler(nil);
}
バージョン番号を報告する
すべてのカスタム イベントは、カスタム イベント アダプタ自体のバージョンと、カスタム イベントがアクセスするサードパーティ SDK のバージョンを、Google Mobile Ads SDK に報告する必要があります。バージョンは GADVersionNumber オブジェクトとして報告されます。
Swift
static func adSDKVersion() -> VersionNumber {
  let versionComponents = String(SampleSDKVersion).components(
    separatedBy: ".")
  if versionComponents.count >= 3 {
    let majorVersion = Int(versionComponents[0]) ?? 0
    let minorVersion = Int(versionComponents[1]) ?? 0
    let patchVersion = Int(versionComponents[2]) ?? 0
    return VersionNumber(
      majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: patchVersion)
  }
  return VersionNumber()
}
static func adapterVersion() -> VersionNumber {
  let versionComponents = String(SampleAdSDK.SampleAdSDKVersionNumber).components(
    separatedBy: ".")
  var version = VersionNumber()
  if versionComponents.count == 4 {
    version.majorVersion = Int(versionComponents[0]) ?? 0
    version.minorVersion = Int(versionComponents[1]) ?? 0
    version.patchVersion = Int(versionComponents[2]) * 100 + Int(versionComponents[3])
  }
  return version
}
Objective-C
+ (GADVersionNumber)adSDKVersion {
  NSArray *versionComponents =
      [SampleSDKVersion componentsSeparatedByString:@"."];
  GADVersionNumber version = {0};
  if (versionComponents.count >= 3) {
    version.majorVersion = [versionComponents[0] integerValue];
    version.minorVersion = [versionComponents[1] integerValue];
    version.patchVersion = [versionComponents[2] integerValue];
  }
  return version;
}
+ (GADVersionNumber)adapterVersion {
  NSArray *versionComponents =
      [SampleCustomEventAdapterVersion componentsSeparatedByString:@"."];
  GADVersionNumber version = {0};
  if (versionComponents.count == 4) {
    version.majorVersion = [versionComponents[0] integerValue];
    version.minorVersion = [versionComponents[1] integerValue];
    version.patchVersion = [versionComponents[2] integerValue] * 100 +
                           [versionComponents[3] integerValue];
  }
  return version;
}
広告をリクエストする
広告をリクエストする方法については、各広告フォーマットの固有手順をご覧ください。