ตั้งค่า
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เหตุการณ์ที่กำหนดเองช่วยให้คุณเพิ่มการแสดงโฆษณาสื่อกลางตามลำดับขั้น (Waterfall Mediation) สำหรับเครือข่ายโฆษณาที่ไม่ใช่เครือข่ายโฆษณาที่รองรับได้ คุณทำได้โดยการใช้
อะแดปเตอร์เหตุการณ์ที่กำหนดเองสำหรับเครือข่ายโฆษณาที่ต้องการผสานรวม
ดูโปรเจ็กต์เหตุการณ์ที่กําหนดเองตัวอย่างฉบับเต็มได้ในที่เก็บ GitHub ของเรา
ข้อกำหนดเบื้องต้น
ก่อนที่จะสร้างเหตุการณ์ที่กําหนดเองได้ คุณต้องผสานรวมรูปแบบโฆษณาต่อไปนี้อย่างใดอย่างหนึ่งเข้ากับแอปก่อน
สร้างเหตุการณ์ที่กำหนดเองใน UI
คุณต้องสร้างเหตุการณ์ที่กำหนดเองใน UI ของ AdMob ก่อน ดูวิธีการในหัวข้อ
เพิ่มเหตุการณ์ที่กำหนดเอง
คุณต้องระบุข้อมูลต่อไปนี้
- ชื่อคลาส
ชื่อที่มีคุณสมบัติครบถ้วนของคลาสที่ใช้การติดตั้งใช้งานอะแดปเตอร์เหตุการณ์ที่กำหนดเอง เช่น
com.google.ads.mediation.sample.customevent.SampleCustomEvent
แนวทางปฏิบัติแนะนำคือเราขอแนะนำให้ใช้คลาสอะแดปเตอร์เดียวสำหรับรูปแบบโฆษณาเหตุการณ์ที่กำหนดเองทั้งหมด
- ป้ายกำกับ
ชื่อที่ไม่ซ้ำกันซึ่งกำหนดแหล่งที่มาของโฆษณา
- พารามิเตอร์
อาร์กิวเมนต์สตริงที่ไม่บังคับซึ่งส่งไปยังอะแดปเตอร์เหตุการณ์ที่กำหนดเอง
เริ่มต้นอะแดปเตอร์
เมื่อ Google Mobile Ads SDK เริ่มต้น
initialize()
จะเรียกใช้ในอะแดปเตอร์ของบุคคลที่สามที่รองรับทั้งหมดและเหตุการณ์ที่กำหนดเองที่กำหนดค่า
สำหรับแอปภายใน UI ของ AdMob ใช้วิธีนี้เพื่อ
ทําการตั้งค่าหรือการเริ่มต้นที่จําเป็นใน SDK ของบุคคลที่สามที่จําเป็น
สําหรับเหตุการณ์ที่กําหนดเอง
Java
package com.google.ads.mediation.sample.customevent;
import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.InitializationCompleteCallback;
import com.google.android.gms.ads.mediation.MediationConfiguration;
public class SampleAdNetworkCustomEvent extends Adapter {
private static final String SAMPLE_AD_UNIT_KEY = "parameter";
@Override
public void initialize(Context context,
InitializationCompleteCallback initializationCompleteCallback,
List<MediationConfiguration> mediationConfigurations) {
// 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.
initializationCompleteCallback.onInitializationSucceeded();
}
}
Kotlin
package com.google.ads.mediation.sample.customevent
import com.google.android.gms.ads.mediation.Adapter
import com.google.android.gms.ads.mediation.InitializationCompleteCallback
import com.google.android.gms.ads.mediation.MediationConfiguration
class SampleCustomEvent : Adapter() {
private val SAMPLE_AD_UNIT_KEY = "parameter"
override fun initialize(
context: Context,
initializationCompleteCallback: InitializationCompleteCallback,
mediationConfigurations: List<MediationConfiguration>
) {
// 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.
initializationCompleteCallback.onInitializationSucceeded()
}
}
รายงานหมายเลขเวอร์ชัน
เหตุการณ์ที่กําหนดเองทั้งหมดต้องรายงานทั้งเวอร์ชันของอแดปเตอร์เหตุการณ์ที่กําหนดเองและเวอร์ชันของ SDK ของบุคคลที่สามที่อินเทอร์เฟซเหตุการณ์ที่กําหนดเองทํางานด้วยไปยัง SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google
ระบบจะรายงานเวอร์ชันเป็นออบเจ็กต์
VersionInfo
Java
package com.google.ads.mediation.sample.customevent;
public class SampleCustomEvent extends Adapter {
@Override
public VersionInfo getVersionInfo() {
String versionString = new VersionInfo(1, 2, 3);
String[] splits = versionString.split("\\.");
if (splits.length >= 4) {
int major = Integer.parseInt(splits[0]);
int minor = Integer.parseInt(splits[1]);
int micro = Integer.parseInt(splits[2]) * 100 + Integer.parseInt(splits[3]);
return new VersionInfo(major, minor, micro);
}
return new VersionInfo(0, 0, 0);
}
@Override
public VersionInfo getSDKVersionInfo() {
String versionString = SampleAdRequest.getSDKVersion();
String[] splits = versionString.split("\\.");
if (splits.length >= 3) {
int major = Integer.parseInt(splits[0]);
int minor = Integer.parseInt(splits[1]);
int micro = Integer.parseInt(splits[2]);
return new VersionInfo(major, minor, micro);
}
return new VersionInfo(0, 0, 0);
}
}
Kotlin
package com.google.ads.mediation.sample.customevent
class SampleCustomEvent : Adapter() {
override fun getVersionInfo(): VersionInfo {
val versionString = VersionInfo(1,2,3).toString()
val splits: List<String> = versionString.split("\\.")
if (splits.count() >= 4) {
val major = splits[0].toInt()
val minor = splits[1].toInt()
val micro = (splits[2].toInt() * 100) + splits[3].toInt()
return VersionInfo(major, minor, micro)
}
return VersionInfo(0, 0, 0)
}
override fun getSDKVersionInfo(): VersionInfo {
val versionString = VersionInfo(1,2,3).toString()
val splits: List<String> = versionString.split("\\.")
if (splits.count() >= 3) {
val major = splits[0].toInt()
val minor = splits[1].toInt()
val micro = splits[2].toInt()
return VersionInfo(major, minor, micro)
}
return VersionInfo(0, 0, 0)
}
}
ขอโฆษณา
หากต้องการขอโฆษณา โปรดดูวิธีการเฉพาะสำหรับรูปแบบโฆษณา
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-02 UTC
[null,null,["อัปเดตล่าสุด 2025-09-02 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 a supported ad format (Banner, Interstitial, Native, or Rewarded) into your app.\u003c/p\u003e\n"],["\u003cp\u003eYou need to create a custom event in the AdMob UI, providing the class name, label, and optional parameter.\u003c/p\u003e\n"],["\u003cp\u003eAll custom event adapters need to report both the adapter and third-party SDK versions to the Google Mobile Ads SDK using \u003ccode\u003eVersionInfo\u003c/code\u003e objects.\u003c/p\u003e\n"],["\u003cp\u003eRefer to format-specific instructions to request an ad after implementing the custom event adapter.\u003c/p\u003e\n"]]],["Custom events enable waterfall mediation for unsupported ad networks by implementing a custom event adapter. This requires creating the event in the AdMob UI, providing a class name, label, and optional parameter. The adapter's `initialize()` method is called during SDK initialization to set up the third-party SDK. All custom events must report their adapter and the third-party SDK's version numbers using `VersionInfo`. Finally, specific instructions to request an ad are available per ad format.\n"],null,["Custom events let you add waterfall mediation for an ad network that isn't a\n[supported ad network](/admob/android/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\nBefore you can create custom events, you must first integrate one of the\nfollowing ad format into your app:\n\n- [Banner](/admob/android/banner)\n- [Interstitial](/admob/android/interstitial)\n- [Native](/admob/android/native)\n- [Rewarded](/admob/android/rewarded)\n\nCreate a custom event in the UI\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 `com.google.ads.mediation.sample.customevent.SampleCustomEvent`. As a best\n practice, we recommend using a single adapter class for all custom event ad\n formats.\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\nInitialize the adapter\n\nWhen Google Mobile Ads SDK initializes,\n\n`initialize()`\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\nJava \n\n package com.google.ads.mediation.sample.customevent;\n\n import com.google.android.gms.ads.mediation.Adapter;\n import com.google.android.gms.ads.mediation.InitializationCompleteCallback;\n import com.google.android.gms.ads.mediation.MediationConfiguration;\n\n public class SampleAdNetworkCustomEvent extends Adapter {\n private static final String SAMPLE_AD_UNIT_KEY = \"parameter\";\n\n @Override\n public void initialize(Context context,\n InitializationCompleteCallback initializationCompleteCallback,\n List\u003cMediationConfiguration\u003e mediationConfigurations) {\n // This is where you will initialize the SDK that this custom\n // event is built for. Upon finishing the SDK initialization,\n // call the completion handler with success.\n initializationCompleteCallback.onInitializationSucceeded();\n }\n }\n\nKotlin \n\n package com.google.ads.mediation.sample.customevent\n\n import com.google.android.gms.ads.mediation.Adapter\n import com.google.android.gms.ads.mediation.InitializationCompleteCallback\n import com.google.android.gms.ads.mediation.MediationConfiguration\n\n class SampleCustomEvent : Adapter() {\n private val SAMPLE_AD_UNIT_KEY = \"parameter\"\n\n override fun initialize(\n context: Context,\n initializationCompleteCallback: InitializationCompleteCallback,\n mediationConfigurations: List\u003cMediationConfiguration\u003e\n ) {\n // This is where you will initialize the SDK that this custom\n // event is built for. Upon finishing the SDK initialization,\n // call the completion handler with success.\n initializationCompleteCallback.onInitializationSucceeded()\n }\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[`VersionInfo`](/admob/android/reference/com/google/android/gms/ads/VersionInfo)\n\nobjects: \n\nJava \n\n package com.google.ads.mediation.sample.customevent;\n\n public class SampleCustomEvent extends Adapter {\n\n @Override\n public VersionInfo getVersionInfo() {\n String versionString = new VersionInfo(1, 2, 3);\n String[] splits = versionString.split(\"\\\\.\");\n\n if (splits.length \u003e= 4) {\n int major = Integer.parseInt(splits[0]);\n int minor = Integer.parseInt(splits[1]);\n int micro = Integer.parseInt(splits[2]) * 100 + Integer.parseInt(splits[3]);\n return new VersionInfo(major, minor, micro);\n }\n\n return new VersionInfo(0, 0, 0);\n }\n\n @Override\n public VersionInfo getSDKVersionInfo() {\n String versionString = SampleAdRequest.getSDKVersion();\n String[] splits = versionString.split(\"\\\\.\");\n\n if (splits.length \u003e= 3) {\n int major = Integer.parseInt(splits[0]);\n int minor = Integer.parseInt(splits[1]);\n int micro = Integer.parseInt(splits[2]);\n return new VersionInfo(major, minor, micro);\n }\n\n return new VersionInfo(0, 0, 0);\n }\n }\n\nKotlin \n\n package com.google.ads.mediation.sample.customevent\n\n class SampleCustomEvent : Adapter() {\n override fun getVersionInfo(): VersionInfo {\n val versionString = VersionInfo(1,2,3).toString()\n val splits: List\u003cString\u003e = versionString.split(\"\\\\.\")\n\n if (splits.count() \u003e= 4) {\n val major = splits[0].toInt()\n val minor = splits[1].toInt()\n val micro = (splits[2].toInt() * 100) + splits[3].toInt()\n return VersionInfo(major, minor, micro)\n }\n\n return VersionInfo(0, 0, 0)\n }\n\n override fun getSDKVersionInfo(): VersionInfo {\n val versionString = VersionInfo(1,2,3).toString()\n val splits: List\u003cString\u003e = versionString.split(\"\\\\.\")\n\n if (splits.count() \u003e= 3) {\n val major = splits[0].toInt()\n val minor = splits[1].toInt()\n val micro = splits[2].toInt()\n return VersionInfo(major, minor, micro)\n }\n\n return VersionInfo(0, 0, 0)\n }\n }\n\nRequest ad\n\nTo request an ad, refer to the instructions specific to the ad format:\n\n- [Banner](/admob/android/custom-events/banner)\n- [Interstitial](/admob/android/custom-events/interstitial)\n- [Native](/admob/android/custom-events/native)\n- [Rewarded](/admob/android/custom-events/rewarded)"]]