אחרי שהמודעה נטענת או לא נטענת, בודקים את האובייקט 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);
}
}
}
}