設定

使用自訂事件,即可為未放送廣告的廣告聯播網新增刊登序列中介服務 支援的廣告聯播網。您自己 只要在您要的廣告聯播網中導入自訂事件轉接程式

必要條件

您必須先整合下列其中一個 導入下列廣告格式:

在使用者介面中建立自訂事件

您必須先在 Ad Manager 中建立自訂事件 第一種是使用無代碼解決方案 AutoML 透過使用者介面建立機器學習模型相關操作說明請參閱: 建立及管理收益 群組

您必須提供以下資訊:

類別名稱

導入自訂事件的類別完整名稱 轉接器,例如 SampleCustomEvent;或者你的課程是以 Swift 為主 MediationExample.SampleCustomEventSwift

如果專案中有多個目標,或是 專案名稱與目標名稱不同。有了目標名稱 看起來會像這樣:appName_targetName.className。另外,請注意 (以底線取代破折號等非英數字元)。 範例

標籤

用於定義廣告來源的專屬名稱。

參數

傳送至自訂事件轉接程式的選用字串引數。

導入 GADMediationAdapter

要建立自訂事件,第一步是導入 SampleCustomEvent 類別所示的 GADMediationAdapter 通訊協定 部分的例子

這個類別負責接收 並委任由 Ad Manager 和 正確的廣告格式

初始化轉接程式

Google Mobile Ads 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 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;
}

請求廣告

如要提出廣告要求,請參閱該廣告格式的操作說明: