استرداد المعلومات المتعلقة باستجابة الإعلان

بعد تحميل إعلان أو تعذُّر تحميله، افحص عنصر ResponseInfo. يقدّم هذا العنصر تفاصيل عن الإعلان الذي تم تحميله والبيانات الوصفية حول تدفق التوسط المستخدَم لمعالجة الطلب.

إذا تم تحميل الإعلان بنجاح، يحتوي مثيل الإعلان على طريقة getResponseInfo. على سبيل المثال، يعرض الإجراء interstitialAd.getResponseInfo معلومات الاستجابة لعنصر InterstitialAd تم تحميله.

إذا تعذّر تحميل إعلان، يمكنك الوصول إلى السمة الاختيارية responseInfo في العنصر LoadAdError، على سبيل المثال، error.responseInfo.

فحص عنصر معلومات الاستجابة

يوفّر عنصر ResponseInfo تفاصيل تشخيصية يتم عرضها من طلب عرض الإعلان.

يعرض المثال التالي معلومات الاستجابة لإعلان تم تحميله:

Android

{
  "responseId": "COOllLGxlPoCFdAx4Aod-Q4A0g",
  "responseExtras": {},
  "loadedAdSourceResponseInfo": {
    "adapterClassName": "com.google.ads.mediation.admob.AdMobAdapter",
    "latencyMillis": 328,
    "name": "Reservation campaign",
    "id": "7068401028668408324",
    "instanceName": "[DO NOT EDIT] Publisher Test Interstitial",
    "instanceId": "4665218928925097",
    "credentials": {},
    "mediationAdError": null
  },
  "adSourceResponses": [
    {
      "adapterClassName": "com.google.ads.mediation.admob.AdMobAdapter",
      "latencyMillis": 328,
      "name": "Reservation campaign",
      "id": "7068401028668408324",
      "instanceName": "[DO NOT EDIT] Publisher Test Interstitial",
      "instanceId": "4665218928925097",
      "credentials": {},
      "mediationAdError": null
    }
  ]
}

iOS

{
  "responseId": "COOllLGxlPoCFdAx4Aod-Q4A0g",
  "responseExtras": {},
  "loadedAdSourceResponseInfo": {
    "adapterClassName": "GADMAdapterGoogleAdMobAds",
    "latencyMillis": 328,
    "name": "Reservation campaign",
    "id": "7068401028668408324",
    "instanceName": "[DO NOT EDIT] Publisher Test Interstitial",
    "instanceId": "4665218928925097",
    "credentials": {},
    "mediationAdError": null
  },
  "adSourceResponses": [
    {
      "adapterClassName": "GADMAdapterGoogleAdMobAds",
      "latencyMillis": 328,
      "name": "Reservation campaign",
      "id": "7068401028668408324",
      "instanceName": "[DO NOT EDIT] Publisher Test Interstitial",
      "instanceId": "4665218928925097",
      "credentials": {},
      "mediationAdError": null
    }
  ]
}

يوفّر الكائن ResponseInfo السمات التالية:

الموقع النوع الوصف
adSourceResponses readonly AdSourceResponseInfo[] قائمة بعناصر AdSourceResponseInfo تمثّل كل محاولة لمصدر إعلان في تدفق التوسط.
loadedAdSourceResponseInfo AdSourceResponseInfo | undefined البيانات الوصفية لمحوِّل مصدر الإعلان الذي حمَّل الإعلان بنجاح إذا لم يتم تحميل الإعلان، تكون هذه القيمة undefined.
responseExtras Readonly<Record<string, unknown>> البيانات الوصفية الإضافية التي يعرضها ردّ الإعلان، مثل مفتاح mediation_group_name
responseId string معرّف فريد لاستجابة الإعلان استخدِم هذا المعرّف لتحديد الإعلانات المحظورة في مركز مراجعة الإعلانات.

قراءة معلومات استجابة مصدر الإعلان

يوفّر عنصر AdSourceResponseInfo بيانات وصفية لمحوّل مضمّن في استجابة الإعلان. يتم إدراج هذه العناصر حسب ترتيب طلب كل مصدر إعلان في تدفق التوسط.

يعرض المثال التالي معلومات استجابة مصدر الإعلان لإعلان تم تحميله:

Android

{
  "adapterClassName": "com.google.ads.mediation.admob.AdMobAdapter",
  "latencyMillis": 328,
  "name": "Reservation campaign",
  "id": "7068401028668408324",
  "instanceName": "[DO NOT EDIT] Publisher Test Interstitial",
  "instanceId": "4665218928925097",
  "credentials": {},
  "mediationAdError": null
}

iOS

{
  "adapterClassName": "GADMAdapterGoogleAdMobAds",
  "latencyMillis": 328,
  "name": "Reservation campaign",
  "id": "7068401028668408324",
  "instanceName": "[DO NOT EDIT] Publisher Test Interstitial",
  "instanceId": "4665218928925097",
  "credentials": {},
  "mediationAdError": null
}

بالنسبة إلى كل مصدر إعلان، يوفّر AdSourceResponseInfo السمات التالية:

الموقع النوع الوصف
adapterClassName string اسم فئة محوِّل شبكة الإعلانات
credentials Readonly<Record<string, string>> المَعلمات من جهة الخادم التي تم ضبطها في واجهة مستخدم AdMob لهذا المحوّل.
id string المعرّف الفريد لمصدر الإعلان
instanceId string المعرّف الفريد لمثيل مصدر الإعلان
instanceName string اسم مثيل مصدر الإعلان
latencyMillis number الوقت المستغرَق بالملي ثانية لمحاولة الاتصال بالشبكة
mediationAdError MediationAdError | undefined إذا تعذّرت محاولة الاتصال بالشبكة، تصف هذه السمة الخطأ. في حال نجاح العملية، تكون هذه القيمة undefined.
name string اسم مصدر الإعلان، على سبيل المثال، "Reservation campaign".

تسجيل معلومات الردّ الكاملة

يتناول هذا القسم عملية تنفيذ لفحص معلومات الاستجابة الكاملة لإعلان تم تحميله.

يسجّل المثال التالي معلومات الاستجابة ويفحصها عند تحميل إعلان أو تعذُّر تحميله:

import {InterstitialAd, LoadAdError} from '@google/mobile-ads';
import type {AdSourceResponseInfo, ResponseInfo} from '@google/mobile-ads';

export async function logResponseInfo(adUnitId: string): Promise<void> {
  try {
    const interstitial = await InterstitialAd.load({adUnitId});
    const responseInfo: ResponseInfo = interstitial.getResponseInfo();

    console.log('Ad Loaded Response ID:', responseInfo.responseId);
    console.log(
      'Loaded Adapter Class Name:',
      responseInfo.loadedAdSourceResponseInfo?.adapterClassName,
    );

    // Inspect each ad source response in the mediation waterfall
    responseInfo.adSourceResponses.forEach(
      (adSourceResponse: AdSourceResponseInfo, index: number) => {
        console.log(
          `Waterfall index ${index}:`,
          adSourceResponse.adapterClassName,
          `Latency: ${adSourceResponse.latencyMillis}ms`,
          adSourceResponse.mediationAdError
            ? `Error: ${adSourceResponse.mediationAdError.message}`
            : 'Success',
        );
      },
    );
  } catch (error) {
    if (error instanceof LoadAdError) {
      console.error('Ad failed to load:', error.message);
      if (error.responseInfo) {
        console.log('Failed Response ID:', error.responseInfo.responseId);
      }
    }
  }
}