设置

借助自定义事件,您可以为不属于某个广告联盟的广告联盟添加广告瀑布流中介 支持的广告联盟。您负责 为此,您可以为要定位的广告联盟 集成。

前提条件

在创建自定义事件之前,您必须先集成 以下广告格式:

在界面中创建自定义事件

必须先在 Ad Manager 中创建自定义事件 界面。有关说明,请参见 创建和管理收益 群组

您需要提供以下信息:

类名称

实现自定义事件的类的完全限定名称 适配器,例如 SampleCustomEvent;或者,如果您的类是在 Swift 中实现的, MediationExample.SampleCustomEventSwift

如果您的项目中有多个目标,或者如果 项目名称与目标名称不同。有了目标名称后 将如下所示:appName_targetName.className。此外,请注意 将短划线等非字母数字字符替换为下划线。 示例

标签

定义广告来源的唯一名称。

参数

传递到自定义事件适配器的可选字符串参数。

实现 GADMediationAdapter

创建自定义事件的第一步是实现 GADMediationAdapter 协议,如 SampleCustomEvent 类所示 (如我们的示例所示)。

该类负责接收来自 将创建广告资源的责任委托给 正确的广告格式。

初始化适配器

在 Google 移动广告 SDK 初始化时 setUpWithConfiguration:completionHandler: 在所有受支持的第三方适配器以及配置的自定义事件上均调用 在 Ad Manager 界面中查看相应应用的详细信息。使用此方法 对所需的第三方 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 移动广告 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;
}

请求广告

若要请求广告,请参阅针对具体广告格式的说明: