Retrieving Information about the Ad Response

For debugging and logging purposes, successfully loaded ads provide a GADResponseInfo object. This object contains information about the ad it loaded. Each ad format class has a property to get the response info. On interstitial ads for example, use the responseInfo property.

For cases where ads fail to load and only an error is available, the GADResponseInfo is available using the key GADErrorUserInfoKeyResponseInfo on the error's userInfo dictionary.

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];
}

Response info properties

Properties of the GADResponseInfo object include:

responseIdentifier
A unique identifier of the ad response. This can be used to identify and block the ad in the Ads Review Center (ARC).
adNetworkClassName
The class name of the ad network that fetched the current ad. Values that can be returned from this property include:

Ad Source Class name
Google Ads Value of GADGoogleAdNetworkClassName.
Rewarded Custom events Your custom event's class name.
All other custom events Value of GADCustomEventAdNetworkClassName.
Mediation The mediation adapter's class name.
adNetworkInfoArray

An array of GADAdNetworkResponseInfo. This array represents the responses received in the mediation waterfall for the ad request.

For each ad network in the waterfall, GADAdNetworkResponseInfo provides:

Property Description
adNetworkClassName A class name that identifies the ad network.
credentials Network configuration set on the Ad Manager UI.
error Error associated with the request to the network. Nil if the network successfully loaded an ad or if the network was not attempted.
latency Amount of time the ad network spent loading an ad. 0 if the network was not attempted.

Querying this property allows you to drill into the outcome of a mediation waterfall for each ad request.

Sample code

Here is a sample snippet from a GADBannerViewDelegate callback implementation:

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);
}

This will print output in the following format when using Google Mobile Ads SDK version 7.60.0 or higher:

  ** Response Info **
    Response ID: 4a_iXpjAJcyN5LcPx6y4mAc
    Network: GADMAdapterGoogleAdMobAds

  ** Mediation line items **
    Entry (1)
    Network: GADMAdapterGoogleAdMobAds
    Credentials:
{
}
    Error: (null)
    Latency: 0.252