カスタム イベントを使用すると、サポートされている広告ネットワークでない広告ネットワーク用に、ウォーターフォール メディエーションを追加できます。そのためには、統合する広告ネットワークに対応するカスタム イベント アダプタを実装します。
GitHub リポジトリで、サンプル カスタム イベント プロジェクト全体を確認できます。
前提条件
カスタム イベントを作成するには、まず次のいずれかの広告フォーマットをアプリに統合しておく必要があります。
管理画面でカスタム イベントを作成する
カスタム イベントは、まず AdMobUI で作成する必要があります。手順については、 カスタム イベントを追加するをご覧ください。
次の情報を指定する必要があります。
- Class Name
カスタム イベント アダプタを実装するクラスの完全修飾名(例:
SampleCustomEvent
。クラスが Swift で実装されている場合はMediationExample.SampleCustomEventSwift
です。プロジェクトに複数のターゲットがある場合、またはプロジェクト名がターゲット名と異なる場合は、ターゲット名が必要です。ターゲット名を使用すると、
appName_targetName.className
のようになります。また、ダッシュなどの英数字以外の文字はアンダースコアに置き換えてください。例。- ラベル
広告ソースを定義する一意の名前。
- パラメータ
カスタム イベント アダプタに渡されるオプションの文字列引数。
GADMediationAdapter を実装する
カスタム イベントを作成する最初のステップは、GADMediationAdapter
プロトコルの実装です。こちらの例の SampleCustomEvent
クラスをご覧ください。
AdMob からメッセージを受信し、適切な広告フォーマットを作成する役割を委任するのは、このクラスの役割です。
アダプターを初期化する
Google Mobile Ads SDK が初期化されると、
setUpWithConfiguration:completionHandler:
は、UI 内でアプリ用に設定された、サポートされているすべてのサードパーティ アダプタとカスタム イベントで呼び出されます。 AdMob このメソッドを使用して、カスタム イベントに必要なサードパーティ 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;
}
広告をリクエスト
広告をリクエストするには、それぞれの広告フォーマットの手順をご覧ください。