ตั้งค่า
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เหตุการณ์ที่กำหนดเองช่วยให้คุณเพิ่มการแสดงโฆษณาสื่อกลางตามลำดับขั้น (Waterfall Mediation) สำหรับเครือข่ายโฆษณาที่ไม่ใช่เครือข่ายโฆษณาที่รองรับได้ คุณทำได้โดยการใช้
อะแดปเตอร์เหตุการณ์ที่กำหนดเองสำหรับเครือข่ายโฆษณาที่ต้องการผสานรวม
ข้อกำหนดเบื้องต้น
ก่อนที่จะสร้างเหตุการณ์ที่กําหนดเองได้ คุณต้องผสานรวมรูปแบบโฆษณาต่อไปนี้อย่างใดอย่างหนึ่งเข้ากับแอปก่อน
สร้างเหตุการณ์ที่กำหนดเองใน UI
คุณต้องสร้างเหตุการณ์ที่กําหนดเองใน UI ของ Ad Manager ก่อน ดูวิธีการได้ที่
สร้างและจัดการกลุ่มผลตอบแทน
คุณต้องระบุข้อมูลต่อไปนี้
- ชื่อคลาส
ชื่อแบบเต็มของคลาสที่ใช้การติดตั้งใช้งานอะแดปเตอร์เหตุการณ์ที่กำหนดเอง เช่น
SampleCustomEvent
หรือหากติดตั้งใช้งานคลาสใน Swift
MediationExample.SampleCustomEventSwift
ต้องระบุชื่อเป้าหมายหากคุณมีเป้าหมายหลายรายการในโปรเจ็กต์ หรือหากชื่อโปรเจ็กต์แตกต่างจากชื่อเป้าหมาย เมื่อใช้ชื่อเป้าหมาย จะมีลักษณะดังนี้ appName_targetName.className
นอกจากนี้ อย่าลืม
แทนที่อักขระที่ไม่ใช่ตัวอักษรและตัวเลข เช่น ขีดกลาง ด้วยขีดล่าง
ตัวอย่าง
- ป้ายกำกับ
ชื่อที่ไม่ซ้ำกันซึ่งกำหนดแหล่งที่มาของโฆษณา
- พารามิเตอร์
อาร์กิวเมนต์สตริงที่ไม่บังคับซึ่งส่งไปยังอะแดปเตอร์เหตุการณ์ที่กำหนดเอง
ขั้นตอนแรกในการสร้างเหตุการณ์ที่กําหนดเองคือการติดตั้งใช้งานGADMediationAdapter
โปรโตคอลตามที่แสดงโดยคลาส SampleCustomEvent
ในตัวอย่างของเรา
คลาสนี้มีหน้าที่รับข้อความจาก Ad Manager และมอบหมายความรับผิดชอบในการสร้างรูปแบบโฆษณาที่ถูกต้อง
เริ่มต้นอะแดปเตอร์
เมื่อ
SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google
เริ่มต้น
setUpWithConfiguration:completionHandler:
จะเรียกใช้ในอะแดปเตอร์ของบุคคลที่สามที่รองรับทั้งหมดและเหตุการณ์ที่กำหนดเองที่กำหนดค่า
สำหรับแอปภายใน UI ของ Ad Manager ใช้วิธีนี้เพื่อ
ทําการตั้งค่าหรือการเริ่มต้นที่จําเป็นใน SDK ของบุคคลที่สามที่จําเป็น
สําหรับเหตุการณ์ที่กําหนดเอง
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);
}
รายงานหมายเลขเวอร์ชัน
เหตุการณ์ที่กำหนดเองทั้งหมดต้องรายงานไปยัง
SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google
ทั้งเวอร์ชันของ
อแดปเตอร์เหตุการณ์ที่กำหนดเองเองและเวอร์ชันของ SDK ของบุคคลที่สามที่
เหตุการณ์ที่กำหนดเองเชื่อมต่อด้วย ระบบจะรายงานเวอร์ชันเป็นออบเจ็กต์
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;
}
ขอโฆษณา
หากต้องการขอโฆษณา โปรดดูวิธีการเฉพาะสำหรับรูปแบบโฆษณา
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-23 UTC
[null,null,["อัปเดตล่าสุด 2025-08-23 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 created in the Ad Manager 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 Ad Manager and delegate ad creation responsibility.\u003c/p\u003e\n"],["\u003cp\u003eCustom events must report both the custom event adapter version and the third-party SDK version to the Google Mobile Ads SDK.\u003c/p\u003e\n"]]],[],null,["Custom events let you add waterfall mediation for an ad network that isn't a\n[supported ad network](/ad-manager/mobile-ads-sdk/ios/choose-networks). You do this by implementing\na custom event adapter for the ad network you want to integrate.\n\nPrerequisites\n\nBefore you can create custom events, you must first integrate one of the\nfollowing ad format into your app:\n\n- [Banner](/ad-manager/mobile-ads-sdk/ios/banner)\n- [Interstitial](/ad-manager/mobile-ads-sdk/ios/interstitial)\n- [Native](/ad-manager/mobile-ads-sdk/ios/native)\n- [Rewarded](/ad-manager/mobile-ads-sdk/ios/rewarded)\n\nCreate a custom event in the UI\n\nA custom event must first be created in the Ad Manager\nUI. See the instructions in\n\n[Create and manage yield\ngroups](//support.google.com/admanager/answer/7390828).\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\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\nAd Manager and delegate the responsibility of creating\nthe correct ad format.\n\nInitialize the adapter\n\nWhen Google Mobile Ads SDK initializes,\n\n`setUpWithConfiguration:completionHandler:`\n\nis invoked on all supported third-party adapters and custom events configured\nfor the app within the Ad Manager UI. Use this method to\nperform any necessary setup or initialization on the required third-party SDK\nfor your custom event. \n\nSwift \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\nObjective-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\nAll custom events must report to Google Mobile Ads SDK both 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`](/ad-manager/mobile-ads-sdk/ios/api/reference/Structs/GADVersionNumber)\n\nobjects: \n\nSwift \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\nObjective-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\nTo request an ad, refer to the instructions specific to the ad format:\n\n- [Banner](/ad-manager/mobile-ads-sdk/ios/custom-events/banner)\n- [Interstitial](/ad-manager/mobile-ads-sdk/ios/custom-events/interstitial)\n- [Native](/ad-manager/mobile-ads-sdk/ios/custom-events/native)\n- [Rewarded](/ad-manager/mobile-ads-sdk/ios/custom-events/rewarded)"]]