الأحداث المخصّصة للإعلانات البينية
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
المتطلبات الأساسية
أكمِل إعداد الأحداث المخصّصة.
طلب إعلان بيني
عند الوصول إلى عنصر العرض الخاص بالحدث المخصّص في سلسلة "توسّط العرض الإعلاني بدون انقطاع"، يتم استدعاء الطريقة loadInterstitialAd()
في اسم الفئة الذي قدّمته عند إنشاء حدث مخصّص. في هذه الحالة، تكون الطريقة في SampleCustomEvent
، التي تستدعي بعد ذلك الطريقة loadInterstitialAd()
في SampleInterstitialCustomEventLoader
.
لطلب إعلان بيني، أنشئ أو عدِّل فئة تتضمّن Adapter
لتنفيذ loadInterstitialAd()
. بالإضافة إلى ذلك، أنشئ فئة جديدة لتنفيذ MediationInterstitialAd
.
في مثال الحدث المخصّص،
توسّع SampleCustomEvent
الفئة Adapter
ثم تفوّض إلى
SampleInterstitialCustomEventLoader
.
Java
package com.google.ads.mediation.sample.customevent;
import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.MediationAdConfiguration;
import com.google.android.gms.ads.mediation.MediationAdLoadCallback;
import com.google.android.gms.ads.mediation.MediationInterstitialAd;
import com.google.android.gms.ads.mediation.MediationInterstitialAdCallback;
...
public class SampleCustomEvent extends Adapter {
private SampleInterstitialCustomEventLoader interstitialLoader;
@Override
public void loadInterstitialAd(
@NonNull MediationInterstitialAdConfiguration adConfiguration,
@NonNull
MediationAdLoadCallback<MediationInterstitialAd, MediationInterstitialAdCallback>
callback) {
interstitialLoader = new SampleInterstitialCustomEventLoader(adConfiguration, callback);
interstitialLoader.loadAd();
}
}
يتحمّل "SampleInterstitialCustomEventLoader
" مسؤولية المهام التالية:
تحميل الإعلان البيني واستدعاء طريقة
MediationAdLoadCallback
بعد اكتمال التحميل
تنفيذ واجهة MediationInterstitialAd
تلقّي عمليات ردّ الاتصال الخاصة بأحداث الإعلانات وإعداد تقارير عنها في حزمة "SDK لإعلانات Google على الأجهزة الجوّالة"
يتم تضمين المَعلمة الاختيارية المحدّدة في واجهة مستخدم AdMob ضمن إعدادات الإعلان. يمكن الوصول إلى المَعلمة من خلال
adConfiguration.getServerParameters().getString(MediationConfiguration.CUSTOM_EVENT_SERVER_PARAMETER_FIELD)
.
تكون هذه المَعلمة عادةً معرّف وحدة إعلانية تتطلّبه حزمة تطوير البرامج (SDK) الخاصة بشبكة إعلانية عند إنشاء عنصر إعلان.
Java
package com.google.ads.mediation.sample.customevent;
import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.MediationInterstitialAdConfiguration;
import com.google.android.gms.ads.mediation.MediationAdLoadCallback;
import com.google.android.gms.ads.mediation.MediationInterstitialAd;
import com.google.android.gms.ads.mediation.MediationInterstitialAdCallback;
...
public class SampleInterstitialCustomEventLoader extends SampleAdListener
implements MediationInterstitialAd {
/** A sample third-party SDK interstitial ad. */
private SampleInterstitial sampleInterstitialAd;
/** Configuration for requesting the interstitial ad from the third-party network. */
private final MediationInterstitialAdConfiguration mediationInterstitialAdConfiguration;
/** Callback for interstitial ad events. */
private MediationInterstitialAdCallback interstitialAdCallback;
/** Callback that fires on loading success or failure. */
private final MediationAdLoadCallback<MediationInterstitialAd, MediationInterstitialAdCallback>
mediationAdLoadCallback;
/** Constructor. */
public SampleInterstitialCustomEventLoader(
@NonNull MediationInterstitialAdConfiguration mediationInterstitialAdConfiguration,
@NonNull MediationAdLoadCallback<MediationInterstitialAd, MediationInterstitialAdCallback>
mediationAdLoadCallback) {
this.mediationInterstitialAdConfiguration = mediationInterstitialAdConfiguration;
this.mediationAdLoadCallback = mediationAdLoadCallback;
}
/** Loads the interstitial ad from the third-party ad network. */
public void loadAd() {
// All custom events have a server parameter named "parameter" that returns
// back the parameter entered into the UI when defining the custom event.
Log.i("InterstitialCustomEvent", "Begin loading interstitial ad.");
String serverParameter = mediationInterstitialAdConfiguration.getServerParameters().getString(
MediationConfiguration.CUSTOM_EVENT_SERVER_PARAMETER_FIELD);
Log.d("InterstitialCustomEvent", "Received server parameter.");
sampleInterstitialAd =
new SampleInterstitial(mediationInterstitialAdConfiguration.getContext());
sampleInterstitialAd.setAdUnit(serverParameter);
// Implement a SampleAdListener and forward callbacks to mediation.
sampleInterstitialAd.setAdListener(this);
// Make an ad request.
Log.i("InterstitialCustomEvent", "start fetching interstitial ad.");
sampleInterstitialAd.fetchAd(
SampleCustomEvent.createSampleRequest(mediationInterstitialAdConfiguration));
}
public SampleAdRequest createSampleRequest(
MediationAdConfiguration mediationAdConfiguration) {
SampleAdRequest request = new SampleAdRequest();
request.setTestMode(mediationAdConfiguration.isTestRequest());
request.setKeywords(mediationAdConfiguration.getMediationExtras().keySet());
return request;
}
}
استنادًا إلى ما إذا تم جلب الإعلان بنجاح أو حدث خطأ، عليك استدعاء onSuccess()
أو onFailure()
.
يتم استدعاء onSuccess()
من خلال تمرير مثيل للفئة التي تنفّذ
MediationInterstitialAd
.
عادةً، يتم تنفيذ هذه الطرق داخل عمليات ردّ الاتصال من حزمة تطوير البرامج (SDK) التابعة لجهة خارجية التي ينفّذها المحوّل. في هذا المثال، تحتوي حزمة تطوير البرامج (SDK) النموذجية على SampleAdListener
مع عمليات رد اتصال ذات صلة:
Java
@Override
public void onAdFetchSucceeded() {
interstitialAdCallback = mediationAdLoadCallback.onSuccess(this);
}
@Override
public void onAdFetchFailed(SampleErrorCode errorCode) {
mediationAdLoadCallback.onFailure(SampleCustomEventError.createSampleSdkError(errorCode));
}
يتطلّب MediationInterstitialAd
تنفيذ طريقة showAd()
لعرض الإعلان:
Java
@Override
public void showAd(@NonNull Context context) {
sampleInterstitialAd.show();
}
بعد استدعاء onSuccess()
، يمكن للمحوّل استخدام عنصر MediationInterstitialAdCallback
الذي تم عرضه لإعادة توجيه أحداث العرض من حزمة تطوير البرامج (SDK) التابعة لجهة خارجية إلى حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة. يمتد الصف
SampleInterstitialCustomEventLoader
إلى الواجهة SampleAdListener
لإعادة توجيه عمليات رد الاتصال من شبكة الإعلانات النموذجية إلى حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة.
من المهم أن يعيد توجيه الحدث المخصّص أكبر عدد ممكن من عمليات معاودة الاتصال هذه، كي يتلقّى تطبيقك الأحداث المكافئة من حزمة SDK لإعلانات Google على الأجهزة الجوّالة. في ما يلي مثال على استخدام دوال رد الاتصال:
Java
@Override
public void onAdFullScreen() {
interstitialAdCallback.reportAdImpression();
interstitialAdCallback.onAdOpened();
}
@Override
public void onAdClosed() {
interstitialAdCallback.onAdClosed();
}
بهذا يكتمل تنفيذ الأحداث المخصّصة للإعلانات البينية. يتوفّر المثال الكامل على GitHub.
يمكنك استخدامها مع شبكة إعلانية متوافقة أو تعديلها لعرض إعلانات بينية للأحداث المخصّصة.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-09-06 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-09-06 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eTo request an interstitial ad with a custom event, create a class extending \u003ccode\u003eAdapter\u003c/code\u003e and implement the \u003ccode\u003eloadInterstitialAd()\u003c/code\u003e method, delegating the loading process to a separate loader class.\u003c/p\u003e\n"],["\u003cp\u003eThe loader class is responsible for loading the ad, implementing the \u003ccode\u003eMediationInterstitialAd\u003c/code\u003e interface, and handling ad event callbacks to the Google Mobile Ads SDK.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful ad fetch, the loader invokes \u003ccode\u003eonSuccess()\u003c/code\u003e on the \u003ccode\u003eMediationAdLoadCallback\u003c/code\u003e, passing an instance of the \u003ccode\u003eMediationInterstitialAd\u003c/code\u003e implementation.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMediationInterstitialAdCallback\u003c/code\u003e is then used to forward ad events, such as impressions and clicks, back to the Google Mobile Ads SDK, ensuring consistent ad tracking and reporting.\u003c/p\u003e\n"],["\u003cp\u003eA full example demonstrating custom event implementation for interstitial ads is available on GitHub for reference and adaptation.\u003c/p\u003e\n"]]],[],null,["Prerequisites\n\nComplete the [custom events setup](/admob/android/custom-events/setup).\n\nRequest an interstitial ad\n\nWhen the custom event line item is reached in the waterfall mediation chain,\nthe `loadInterstitialAd()` method is called on the class name you provided when\n[creating a custom\nevent](/admob/android/custom-events/setup#create). In this case,\nthat method is in `SampleCustomEvent`, which then calls the\n`loadInterstitialAd()` method in `SampleInterstitialCustomEventLoader`.\n\nTo request an interstitial ad, create or modify a class that extends `Adapter`\nto implement `loadInterstitialAd()`. Additionally, create a new class to\nimplement `MediationInterstitialAd`.\n\nIn our [custom event example](//github.com/googleads/googleads-mobile-android-mediation/blob/main/Example/customevent/src/main/java/com/google/ads/mediation/sample/customevent/SampleCustomEvent.java),\n`SampleCustomEvent` extends the `Adapter` class and then delegates to\n`SampleInterstitialCustomEventLoader`. \n\nJava \n\n```java\npackage com.google.ads.mediation.sample.customevent;\n\nimport com.google.android.gms.ads.mediation.Adapter;\nimport com.google.android.gms.ads.mediation.MediationAdConfiguration;\nimport com.google.android.gms.ads.mediation.MediationAdLoadCallback;\nimport com.google.android.gms.ads.mediation.MediationInterstitialAd;\nimport com.google.android.gms.ads.mediation.MediationInterstitialAdCallback;\n...\n\npublic class SampleCustomEvent extends Adapter {\n private SampleInterstitialCustomEventLoader interstitialLoader;\n @Override\n public void loadInterstitialAd(\n @NonNull MediationInterstitialAdConfiguration adConfiguration,\n @NonNull\n MediationAdLoadCallback\u003cMediationInterstitialAd, MediationInterstitialAdCallback\u003e\n callback) {\n interstitialLoader = new SampleInterstitialCustomEventLoader(adConfiguration, callback);\n interstitialLoader.loadAd();\n }\n}\n```\n\n`SampleInterstitialCustomEventLoader` is responsible for the following tasks:\n\n- Loading the interstitial ad and invoking a\n [`MediationAdLoadCallback`](/admob/android/reference/com/google/android/gms/ads/mediation/MediationAdLoadCallback)\n method once loading completes.\n\n- Implementing the `MediationInterstitialAd` interface.\n\n- Receiving and reporting ad event callbacks to Google Mobile Ads SDK.\n\nThe optional parameter defined in the AdMob UI is\nincluded in the ad configuration. The parameter can be accessed through\n`adConfiguration.getServerParameters().getString(MediationConfiguration.CUSTOM_EVENT_SERVER_PARAMETER_FIELD)`.\nThis parameter is typically an ad unit identifier that an ad network SDK\nrequires when instantiating an ad object. \n\nJava \n\n```java\npackage com.google.ads.mediation.sample.customevent;\n\nimport com.google.android.gms.ads.mediation.Adapter;\nimport com.google.android.gms.ads.mediation.MediationInterstitialAdConfiguration;\nimport com.google.android.gms.ads.mediation.MediationAdLoadCallback;\nimport com.google.android.gms.ads.mediation.MediationInterstitialAd;\nimport com.google.android.gms.ads.mediation.MediationInterstitialAdCallback;\n...\n\npublic class SampleInterstitialCustomEventLoader extends SampleAdListener\n implements MediationInterstitialAd {\n\n /** A sample third-party SDK interstitial ad. */\n private SampleInterstitial sampleInterstitialAd;\n\n /** Configuration for requesting the interstitial ad from the third-party network. */\n private final MediationInterstitialAdConfiguration mediationInterstitialAdConfiguration;\n\n /** Callback for interstitial ad events. */\n private MediationInterstitialAdCallback interstitialAdCallback;\n\n /** Callback that fires on loading success or failure. */\n private final MediationAdLoadCallback\u003cMediationInterstitialAd, MediationInterstitialAdCallback\u003e\n mediationAdLoadCallback;\n\n /** Constructor. */\n public SampleInterstitialCustomEventLoader(\n @NonNull MediationInterstitialAdConfiguration mediationInterstitialAdConfiguration,\n @NonNull MediationAdLoadCallback\u003cMediationInterstitialAd, MediationInterstitialAdCallback\u003e\n mediationAdLoadCallback) {\n this.mediationInterstitialAdConfiguration = mediationInterstitialAdConfiguration;\n this.mediationAdLoadCallback = mediationAdLoadCallback;\n }\n\n /** Loads the interstitial ad from the third-party ad network. */\n public void loadAd() {\n // All custom events have a server parameter named \"parameter\" that returns\n // back the parameter entered into the UI when defining the custom event.\n Log.i(\"InterstitialCustomEvent\", \"Begin loading interstitial ad.\");\n String serverParameter = mediationInterstitialAdConfiguration.getServerParameters().getString(\n MediationConfiguration.CUSTOM_EVENT_SERVER_PARAMETER_FIELD);\n Log.d(\"InterstitialCustomEvent\", \"Received server parameter.\");\n\n sampleInterstitialAd =\n new SampleInterstitial(mediationInterstitialAdConfiguration.getContext());\n sampleInterstitialAd.setAdUnit(serverParameter);\n\n // Implement a SampleAdListener and forward callbacks to mediation.\n sampleInterstitialAd.setAdListener(this);\n\n // Make an ad request.\n Log.i(\"InterstitialCustomEvent\", \"start fetching interstitial ad.\");\n sampleInterstitialAd.fetchAd(\n SampleCustomEvent.createSampleRequest(mediationInterstitialAdConfiguration));\n }\n\npublic SampleAdRequest createSampleRequest(\n MediationAdConfiguration mediationAdConfiguration) {\n SampleAdRequest request = new SampleAdRequest();\n request.setTestMode(mediationAdConfiguration.isTestRequest());\n request.setKeywords(mediationAdConfiguration.getMediationExtras().keySet());\n return request;\n }\n}\n```\n\nDepending on whether the ad is successfully fetched or encounters an error, you\nwould call either\n[`onSuccess()`](/admob/android/reference/com/google/android/gms/ads/mediation/MediationAdLoadCallback#onSuccess(MediationAdT))\nor\n[`onFailure()`](/admob/android/reference/com/google/android/gms/ads/mediation/MediationAdLoadCallback#onFailure(com.google.android.gms.ads.AdError)).\n`onSuccess()` is called by passing in an instance of the class that implements\n`MediationInterstitialAd`.\n\nTypically, these methods are implemented inside callbacks from the\nthird-party SDK your adapter implements. For this example, the Sample SDK\nhas a `SampleAdListener` with relevant callbacks: \n\nJava \n\n```java\n@Override\npublic void onAdFetchSucceeded() {\n interstitialAdCallback = mediationAdLoadCallback.onSuccess(this);\n}\n\n@Override\npublic void onAdFetchFailed(SampleErrorCode errorCode) {\n mediationAdLoadCallback.onFailure(SampleCustomEventError.createSampleSdkError(errorCode));\n}\n```\n\n`MediationInterstitialAd` requires implementing a `showAd()` method to display\nthe ad: \n\nJava \n\n```java\n@Override\npublic void showAd(@NonNull Context context) {\n sampleInterstitialAd.show();\n}\n```\n\nForward mediation events to Google Mobile Ads SDK\n\nOnce `onSuccess()` is called, the returned `MediationInterstitialAdCallback`\nobject can then be used by the adapter to forward presentation events from the\nthird-party SDK to Google Mobile Ads SDK. The\n`SampleInterstitialCustomEventLoader` class extends the `SampleAdListener`\ninterface to forward callbacks from the sample ad network to the Google Mobile\nAds SDK.\n\nIt's important that your custom event forwards as many of these callbacks as\npossible, so that your app receives these equivalent events from the Google\nMobile Ads SDK. Here's an example of using callbacks: \n\nJava \n\n```java\n@Override\npublic void onAdFullScreen() {\n interstitialAdCallback.reportAdImpression();\n interstitialAdCallback.onAdOpened();\n}\n\n@Override\npublic void onAdClosed() {\n interstitialAdCallback.onAdClosed();\n}\n```\n\nThis completes the custom events implementation for interstitial ads. The full\nexample is available on\n[GitHub](//github.com/googleads/googleads-mobile-android-mediation/tree/master/Example/customevent/src/main/java/com/google/ads/mediation/sample/customevent).\nYou can use it with an ad network that is already supported or modify it to\ndisplay custom event interstitial ads."]]