設定

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

前提条件

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

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

カスタム イベントは、まず管理画面で Ad Manager作成する必要があります。手順については、 収益グループを作成、管理するをご覧ください。

次の情報が必要です。

Class Name

カスタム イベント アダプタを実装するクラスの完全修飾名(例: SampleCustomEvent。クラスが Swift で実装されている場合は MediationExample.SampleCustomEventSwift です。

プロジェクトに複数のターゲットがある場合や、プロジェクト名がターゲット名と異なる場合は、ターゲット名が必要です。ターゲット名を付けると、appName_targetName.className のようになります。また、ダッシュなどの英数字以外の文字はアンダースコアに置き換えてください。

ラベル

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

パラメータ

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

GADMediationAdapter を実装する

カスタム イベントを作成するための最初のステップは、こちらの例SampleCustomEvent クラスに示されている GADMediationAdapter プロトコルの実装です。

Ad Manager からメッセージを受信し、適切な広告フォーマットを作成する役割を委任するのは、このクラスの役割です。

アダプターを初期化する

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

Swift

import GoogleMobileAds

class SampleCustomEvent: NSObject, GADMediationAdapter {

  static func setUpWith(
    _ configuration: GADMediationServerConfiguration,
    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() -> GADVersionNumber {
  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 GADVersionNumber(
      majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: patchVersion)
  }

  return GADVersionNumber()
}

static func adapterVersion() -> GADVersionNumber {
  let versionComponents = String(SampleAdSDK.SampleAdSDKVersionNumber).components(
    separatedBy: ".")
  var version = GADVersionNumber()
  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;
}

広告をリクエスト

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