デバッグとロギング用の場合、正常に読み込まれた広告は GADResponseInfo
オブジェクトを提供します。このオブジェクトには、読み込まれた広告に関する情報が含まれます。各広告フォーマット クラスには、レスポンス情報を取得するためのプロパティがあります。たとえばインタースティシャル広告の場合は、responseInfo
プロパティを使用します。
広告の読み込みに失敗してエラーだけが返された場合は、そのエラーの userInfo
リスト上のキー GADErrorUserInfoKeyResponseInfo
を使って GADResponseInfo
を取得できます。
Swift
func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) { let responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo] as? GADResponseInfo }
Objective-C
- (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error { GADResponseInfo *responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo]; }
レスポンス情報のプロパティ
GADResponseInfo
オブジェクトのプロパティには、以下が含まれます。
- responseIdentifier
- 広告レスポンスごとに固有の ID。広告レビュー センター(ARC)で広告を識別してブロックするために使用されます。
- adNetworkClassName
- 現在の広告を取得した広告ネットワークのクラス名。このプロパティから返される値には、次の要素が含まれる可能性があります。
広告ソース クラス名 Google 広告 GADGoogleAdNetworkClassName
の値。リワード カスタム イベント カスタム イベントのクラス名。 他のすべてのカスタム イベント GADCustomEventAdNetworkClassName
の値。メディエーション メディエーション アダプタのクラス名。 - adNetworkInfoArray
GADAdNetworkResponseInfo
の配列。この配列は、広告リクエストに対してメディエーション ウォーターフォールで受け取ったレスポンスを表します。ウォーターフォール内の広告ネットワークごとに、
GADAdNetworkResponseInfo
が次の情報を提供します。プロパティ 説明 adNetworkClassName
広告ネットワークを識別するクラス名。 credentials
AdMob 管理画面で設定されているネットワーク設定。 error
ネットワークへのリクエストに関連付けられたエラー。ネットワークが広告を正常に読み込んだか、読み込みを試行しなかった場合は null。 latency
広告ネットワークが広告の読み込みに費やした時間。読み込みを試行しなかった場合は 0
。このプロパティにクエリを送ると、広告リクエストごとにメディエーション ウォーターフォールの結果を詳しく確認できます。
サンプルコード
次に示すのは GADBannerViewDelegate
コールバックの実装のサンプル スニペットです。
Swift
func adViewDidReceiveAd(_ bannerView: GADBannerView) { print("adViewDidReceiveAd") if let responseInfo = bannerView.responseInfo { print(responseInfo) } } func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) { print("didFailToReceiveAdWithError: \(error.localizedDescription)") // GADBannerView has the responseInfo property but this demonstrates accessing // response info from a returned NSError. if let responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo] as? GADResponseInfo { print(responseInfo) } }
Objective-C
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView { NSLog(@"adViewDidReceiveAd"); NSLog(@"\n%@", responseInfo); } - (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error { NSLog(@"didFailToReceiveAdWithError: %@", error.localizedDescription); // GADBannerView has the responseInfo property but this demonstrates accessing response info // from a returned NSError. GADResponseInfo *responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo]; NSLog(@"\n%@", responseInfo); }
これにより、Google Mobile Ads SDK バージョン 7.60.0 以降を使った場合に、次の形式で結果が出力されます。
** Response Info **
Response ID: 4a_iXpjAJcyN5LcPx6y4mAc
Network: GADMAdapterGoogleAdMobAds
** Mediation line items **
Entry (1)
Network: GADMAdapterGoogleAdMobAds
Credentials:
{
}
Error: (null)
Latency: 0.252