Thiết lập
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Sự kiện tuỳ chỉnh cho phép bạn thêm chế độ dàn xếp kiểu thác nước cho một mạng quảng cáo không thuộc danh sách
mạng quảng cáo được hỗ trợ. Bạn có thể thêm chế độ dàn xếp này bằng cách triển khai bộ chuyển đổi sự kiện tuỳ chỉnh cho mạng quảng cáo mà bạn muốn tích hợp.
Bạn có thể tìm thấy một dự án sự kiện tuỳ chỉnh mẫu đầy đủ trong kho lưu trữ GitHub.
Điều kiện tiên quyết
Để có thể tạo sự kiện tuỳ chỉnh, trước tiên bạn phải tích hợp một trong các định dạng quảng cáo sau đây vào ứng dụng của mình:
Tạo sự kiện tuỳ chỉnh trong giao diện người dùng
Trước tiên, bạn phải tạo một sự kiện tuỳ chỉnh trong giao diện người dùng AdMob. Hãy xem hướng dẫn trong phần
Thêm sự kiện tuỳ chỉnh.
Bạn cần phải cung cấp các thông tin sau:
- Tên lớp
Tên đủ điều kiện của lớp triển khai bộ chuyển đổi sự kiện tuỳ chỉnh – ví dụ:
SampleCustomEvent
; hoặc nếu lớp của bạn được triển khai trong Swift, hãy dùng MediationExample.SampleCustomEventSwift
.
Bạn phải nhập tên mục tiêu nếu có nhiều mục tiêu trong dự án hoặc nếu tên dự án khác với tên mục tiêu. Tên mục tiêu sẽ
giống như sau: appName_targetName.className
. Ngoài ra, hãy nhớ thay thế mọi ký tự không phải chữ-số (ví dụ như thay thế dấu gạch ngang bằng dấu gạch dưới).
Ví dụ.
- Hãng nhạc
Tên duy nhất để xác định nguồn quảng cáo.
- Thông số
Một đối số chuỗi không bắt buộc được truyền đến bộ chuyển đổi sự kiện tuỳ chỉnh.
Để tạo sự kiện tuỳ chỉnh, trước tiên, bạn cần triển khai giao thức GADMediationAdapter
như hiển thị bởi lớp SampleCustomEvent
trong ví dụ của chúng tôi.
Lớp này có trách nhiệm nhận thông báo từ AdMob và uỷ quyền tạo định dạng quảng cáo chính xác.
Khởi chạy bộ chuyển đổi
Khi SDK quảng cáo trên thiết bị di động của Google khởi chạy,
setUpWithConfiguration:completionHandler:
sẽ được gọi trên tất cả các sự kiện tuỳ chỉnh và bộ chuyển đổi bên thứ ba được hỗ trợ đã định cấu hình
cho ứng dụng đó trong giao diện người dùng AdMob. Hãy sử dụng phương thức này để thực hiện mọi thao tác thiết lập hoặc khởi chạy cần thiết trên SDK bắt buộc của bên thứ ba cho sự kiện tuỳ chỉnh của bạn.
Swift
import GoogleMobileAds
class SampleCustomEvent: NSObject, MediationAdapter {
static func setUpWith(
_ configuration: MediationServerConfiguration,
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);
}
Báo cáo số phiên bản
Tất cả sự kiện tuỳ chỉnh phải báo cáo cho SDK quảng cáo trên thiết bị di động của Google thông tin về cả phiên bản của bộ chuyển đổi sự kiện tuỳ chỉnh và phiên bản SDK của bên thứ ba mà sự kiện tuỳ chỉnh liên kết đến. Các phiên bản được báo cáo dưới dạng đối tượng
GADVersionNumber
Swift
static func adSDKVersion() -> VersionNumber {
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 VersionNumber(
majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: patchVersion)
}
return VersionNumber()
}
static func adapterVersion() -> VersionNumber {
let versionComponents = String(SampleAdSDK.SampleAdSDKVersionNumber).components(
separatedBy: ".")
var version = VersionNumber()
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;
}
Yêu cầu quảng cáo
Để yêu cầu hiển thị một quảng cáo, hãy tham khảo hướng dẫn cụ thể cho định dạng quảng cáo đó:
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eCustom events allow you to add waterfall mediation for unsupported ad networks by implementing a custom event adapter.\u003c/p\u003e\n"],["\u003cp\u003eBefore creating custom events, you must integrate an ad format (Banner, Interstitial, Native, or Rewarded) into your app.\u003c/p\u003e\n"],["\u003cp\u003eA custom event needs to be defined in the AdMob UI, requiring a Class Name, Label, and optional Parameter.\u003c/p\u003e\n"],["\u003cp\u003eYou must implement the \u003ccode\u003eGADMediationAdapter\u003c/code\u003e protocol to receive messages from AdMob and delegate ad format creation.\u003c/p\u003e\n"],["\u003cp\u003eThe adapter needs to be initialized, report version numbers, and request ads following format-specific instructions.\u003c/p\u003e\n"]]],["Custom events enable adding waterfall mediation for unsupported ad networks by implementing a custom event adapter. First, create the custom event in the AdMob UI, supplying a class name, label, and optional parameter. Implement the `GADMediationAdapter` protocol, including the `setUpWithConfiguration` method for SDK initialization. Report the custom event adapter and third-party SDK versions using `GADVersionNumber`. Finally, refer to ad format-specific instructions to request an ad. This is all handled in a custom event class.\n"],null,["# Setup\n\nCustom events let you add waterfall mediation for an ad network that isn't a\n[supported ad network](/admob/ios/choose-networks). You do this by implementing\na custom event adapter for the ad network you want to integrate.\n\nYou can find a full sample custom event project in our [GitHub\nrepo](//github.com/googleads/googleads-mobile-android-mediation).\n\nPrerequisites\n-------------\n\nBefore you can create custom events, you must first integrate one of the\nfollowing ad format into your app:\n\n- [Banner](/admob/ios/banner)\n- [Interstitial](/admob/ios/interstitial)\n- [Native](/admob/ios/native)\n- [Rewarded](/admob/ios/rewarded)\n\nCreate a custom event in the UI\n-------------------------------\n\nA custom event must first be created in the AdMob\nUI. See the instructions in\n\n[Add a custom event](//support.google.com/admob/answer/3083407).\n\n\nYou need to supply the following:\n\nClass Name\n\n: The fully-qualified name of the class that implements the custom event\n adapter---for example,\n\n `SampleCustomEvent`; or if your class is implemented in Swift,\n `MediationExample.SampleCustomEventSwift`.\n\n Target name is required if you have multiple targets in your project or if\n the project name is different from the target name. With the target name, it\n would look like this: `appName_targetName.className`. In addition, remember\n to replace any non-alphanumeric characters such as dashes with underscores.\n [Example](//maximbilan.medium.com/ios-objective-c-project-nsclassfromstring-method-for-swift-classes-dbadb721723).\n\nLabel\n\n: A unique name defining the ad source.\n\nParameter\n\n: An optional string argument passed to your custom event adapter.\n\nImplement GADMediationAdapter\n-----------------------------\n\nThe first step to creating a custom event is implementing the\n`GADMediationAdapter` protocol as shown by the `SampleCustomEvent` class\nin [our example](//github.com/googleads/googleads-mobile-ios-mediation).\n\nIt is the responsibility of this class to receive messages from\nAdMob and delegate the responsibility of creating\nthe correct ad format.\n\nInitialize the adapter\n----------------------\n\nWhen\n\nGoogle Mobile Ads SDK\n\ninitializes,\n\n`setUpWithConfiguration:completionHandler:`\n\nis invoked on all supported third-party adapters and custom events configured\nfor the app within the AdMob UI. Use this method to\nperform any necessary setup or initialization on the required third-party SDK\nfor your custom event. \n\n### Swift\n\n import GoogleMobileAds\n\n class SampleCustomEvent: NSObject, MediationAdapter {\n\n static func setUpWith(\n _ configuration: MediationServerConfiguration,\n completionHandler: @escaping GADMediationAdapterSetUpCompletionBlock\n ) {\n // This is where you will initialize the SDK that this custom event is built\n // for. Upon finishing the SDK initialization, call the completion handler\n // with success.\n completionHandler(nil)\n }\n }\n\n### Objective-C\n\n #import \"SampleCustomEvent.h\"\n\n @implementation SampleCustomEvent\n\n + (void)setUpWithConfiguration:(nonnull GADMediationServerConfiguration *)configuration\n completionHandler:(nonnull GADMediationAdapterSetUpCompletionBlock)completionHandler {\n // This is where you initialize the SDK that this custom event is built\n // for. Upon finishing the SDK initialization, call the completion handler\n // with success.\n completionHandler(nil);\n }\n\nReport version numbers\n----------------------\n\nAll custom events must report to\n\nGoogle Mobile Ads SDK\n\nboth the version of\nthe custom event adapter itself and the version of the third-party SDK the\ncustom event interfaces with. Versions are reported as\n\n[`GADVersionNumber`](/admob/ios/api/reference/Structs/GADVersionNumber)\n\nobjects: \n\n### Swift\n\n static func adSDKVersion() -\u003e VersionNumber {\n let versionComponents = String(SampleSDKVersion).components(\n separatedBy: \".\")\n\n if versionComponents.count \u003e= 3 {\n let majorVersion = Int(versionComponents[0]) ?? 0\n let minorVersion = Int(versionComponents[1]) ?? 0\n let patchVersion = Int(versionComponents[2]) ?? 0\n\n return VersionNumber(\n majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: patchVersion)\n }\n\n return VersionNumber()\n }\n\n static func adapterVersion() -\u003e VersionNumber {\n let versionComponents = String(SampleAdSDK.SampleAdSDKVersionNumber).components(\n separatedBy: \".\")\n var version = VersionNumber()\n if versionComponents.count == 4 {\n version.majorVersion = Int(versionComponents[0]) ?? 0\n version.minorVersion = Int(versionComponents[1]) ?? 0\n version.patchVersion = Int(versionComponents[2]) * 100 + Int(versionComponents[3])\n }\n return version\n }\n\n### Objective-C\n\n + (GADVersionNumber)adSDKVersion {\n NSArray *versionComponents =\n [SampleSDKVersion componentsSeparatedByString:@\".\"];\n GADVersionNumber version = {0};\n if (versionComponents.count \u003e= 3) {\n version.majorVersion = [versionComponents[0] integerValue];\n version.minorVersion = [versionComponents[1] integerValue];\n version.patchVersion = [versionComponents[2] integerValue];\n }\n return version;\n }\n\n + (GADVersionNumber)adapterVersion {\n NSArray *versionComponents =\n [SampleCustomEventAdapterVersion componentsSeparatedByString:@\".\"];\n GADVersionNumber version = {0};\n if (versionComponents.count == 4) {\n version.majorVersion = [versionComponents[0] integerValue];\n version.minorVersion = [versionComponents[1] integerValue];\n version.patchVersion = [versionComponents[2] integerValue] * 100 +\n [versionComponents[3] integerValue];\n }\n return version;\n }\n\nRequest ad\n----------\n\nTo request an ad, refer to the instructions specific to the ad format:\n\n- [Banner](/admob/ios/custom-events/banner)\n- [Interstitial](/admob/ios/custom-events/interstitial)\n- [Native](/admob/ios/custom-events/native)\n- [Rewarded](/admob/ios/custom-events/rewarded)"]]