設定

カスタム イベントを使用すると、 サポートされている広告ネットワークのいずれかを選択します。あなたは それには、目的の広告ネットワークにカスタム イベント アダプタを実装し、 統合できます

前提条件

カスタム イベントを作成するには、まず アプリに実装することをおすすめします

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

まずアド マネージャーでカスタム イベントを作成する必要があります UI です。手順については、次をご覧ください: 収益の作成と管理 できます

以下を指定する必要があります。

クラス名

カスタム イベントを実装するクラスの完全修飾名 たとえば、 SampleCustomEvent、クラスが Swift で実装されている場合は MediationExample.SampleCustomEventSwift

プロジェクトに複数のターゲットがある場合や、 プロジェクト名はターゲット名とは異なります。ターゲット名を使用すると、 appName_targetName.className のようになります。また を使用すると、ダッシュなどの英数字以外の文字はアンダースコアに置き換えられます。

ラベル

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

パラメータ

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

GADMediationAdapter を実装する

カスタム イベントを作成するには、まず SampleCustomEvent クラスが示す GADMediationAdapter プロトコル こちらの例をご覧ください。

外部からメッセージを受信することは、このクラスが担います。 アド マネージャーでアド マネージャーを作成し、 適切な広告フォーマットです

アダプターを初期化する

Google Mobile Ads SDK が初期化されると setUpWithConfiguration:completionHandler: サポートされているすべてのサードパーティ アダプタと、構成済みのカスタム イベントで呼び出される アド マネージャーの管理画面で [アプリ]を選択してくださいこの方法は、 必要なサードパーティ 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);
}

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

すべてのカスタム イベントは、Google Mobile Ads SDK に カスタム イベント アダプタ自体とサードパーティ 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;
}

広告をリクエスト

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