بازیابی اطلاعات درباره پاسخ آگهی

پس‌از بار شدن یا نشدن آگهی، شیء 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 شناسه یکتای پاسخ آگهی. از این شناسه برای شناسایی آگهی‌های مسدودکننده در مرکز بررسی آگهی‌ها (ARC) استفاده کنید.

اطلاعات پاسخ منبع آگهی را بخوانید

شیء 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);
      }
    }
  }
}