出于调试和日志记录目的,成功加载的广告会提供 ResponseInfo 对象。除了用于加载广告的中介广告瀑布流的相关信息之外,此对象还包含有关它所加载的广告的信息。
如果广告加载成功,广告对象会有一个 GetResponseInfo() 方法。例如,interstitialAd.GetResponseInfo() 可获取已加载的插页式广告的响应信息。
如果广告未能加载且系统只显示了一条错误,可通过 LoadAdError.GetResponseInfo() 获取响应信息。
private void LoadInterstitialAd()
{
  AdRequest adRequest = new AdRequest();
  InterstitialAd.Load("AD_UNIT_ID", adRequest, (InterstitialAd insterstitialAd, LoadAdError error) =>
  {
    // If the operation failed with a reason.
    if (error != null)
    {
        ResponseInfo errorInfo = error.GetResponseInfo();
        Debug.LogError("Interstitial ad failed to load an ad with error : " + error);
        return;
    }
    ResponseInfo loadInfo = insterstitialAd.GetResponseInfo();
  });
}
响应信息
以下是 ResponseInfo.ToString() 返回的输出示例,显示了针对已加载的广告返回的调试数据:
Android
{ "Response ID": "COOllLGxlPoCFdAx4Aod-Q4A0g", "Mediation Adapter Class Name": "com.google.ads.mediation.admob.AdMobAdapter", "Adapter Responses": [ { "Adapter": "com.google.ads.mediation.admob.AdMobAdapter", "Latency": 328, "Ad Source Name": "Reservation campaign", "Ad Source ID": "7068401028668408324", "Ad Source Instance Name": "[DO NOT EDIT] Publisher Test Interstitial", "Ad Source Instance ID": "4665218928925097", "Credentials": {}, "Ad Error": "null" } ], "Loaded Adapter Response": { "Adapter": "com.google.ads.mediation.admob.AdMobAdapter", "Latency": 328, "Ad Source Name": "Reservation campaign", "Ad Source ID": "7068401028668408324", "Ad Source Instance Name": "[DO NOT EDIT] Publisher Test Interstitial", "Ad Source Instance ID": "4665218928925097", "Credentials": {}, "Ad Error": "null" }, "Response Extras": { "mediation_group_name": "Campaign" } }
iOS
** Response Info ** Response ID: CIzs0ZO5kPoCFRqWAAAdJMINpQ Network: GADMAdapterGoogleAdMobAds ** Loaded Adapter Response ** Network: GADMAdapterGoogleAdMobAds Ad Source Name: Reservation campaign Ad Source ID: 7068401028668408324 Ad Source Instance Name: [DO NOT EDIT] Publisher Test Interstitial Ad Source Instance ID: [DO NOT EDIT] Publisher Test Interstitial AdUnitMapping: { } Error: (null) Latency: 0.391 ** Extras Dictionary ** { "mediation_group_name" = Campaign; } ** Mediation line items ** Entry (1) Network: GADMAdapterGoogleAdMobAds Ad Source Name: Reservation campaign Ad Source ID:7068401028668408324 Ad Source Instance Name: [DO NOT EDIT] Publisher Test Interstitial Ad Source Instance ID: [DO NOT EDIT] Publisher Test Interstitial AdUnitMapping: { } Error: (null) Latency: 0.391
针对 ResponseInfo 对象的方法包括:
| 方法 | 说明 | 
|---|---|
| GetAdapterResponses | 返回 AdapterResponseInfo列表,其中具有广告响应中包含的每个适配器的元数据。可用于调试广告瀑布流中介和出价的执行情况。该列表的顺序与此广告请求的中介广告瀑布流的顺序一致。如需了解详情,请参阅适配器响应信息。 | 
| GetLoadedAdapterResponseInfo | 返回加载了广告的适配器所对应的 AdapterResponseInfo。 | 
| GetMediationAdapterClassName | 返回加载了广告的广告联盟的中介适配器类名称。 | 
| GetResponseId | 响应标识符是广告响应的唯一标识符。此标识符可用于在广告审核中心 (ARC) 中识别和屏蔽广告。 | 
| GetResponseExtras | 返回有关广告响应的额外信息。Extras 可返回以下键: 
 | 
以下示例展示了如何从加载的 ResponseInfo 读取值:
private void LoadInterstitialAd()
{
  AdRequest adRequest = new AdRequest();
  InterstitialAd.Load("AD_UNIT_ID", adRequest, (InterstitialAd insterstitialAd, LoadAdError error) =>
  {
    // If the operation failed with a reason.
    if (error != null)
    {
        Debug.LogError("Interstitial ad failed to load an ad with error : " + error);
        return;
    }
    ResponseInfo responseInfo = insterstitialAd.GetResponseInfo();
    string responseId = responseInfo.GetResponseId();
    string mediationAdapterClassName = responseInfo.GetMediationAdapterClassName();
    List<AdapterResponseInfo> adapterResponses = responseInfo.GetAdapterResponses();
    AdapterResponseInfo loadedAdapterResponseInfo = responseInfo.GetLoadedAdapterResponseInfo();
    Dictionary<string, string> extras = responseInfo.GetResponseExtras();
    string mediationGroupName = extras["mediation_group_name"];
    string mediationABTestName = extras["mediation_ab_test_name"];
    string mediationABTestVariant = extras["mediation_ab_test_variant"]; 
  });
}
适配器响应信息
AdapterResponseInfo 具有广告响应中包含的每个适配器的元数据,可用于调试广告瀑布流中介和出价的执行情况。该列表的顺序与广告请求的中介广告瀑布流的顺序一致。
以下是 AdapterResponseInfo 返回的输出示例:
Android
{ "Adapter": "com.google.ads.mediation.admob.AdMobAdapter", "Latency": 328, "Ad Source Name": "Reservation campaign", "Ad Source ID": "7068401028668408324", "Ad Source Instance Name": "[DO NOT EDIT] Publisher Test Interstitial", "Ad Source Instance ID": "4665218928925097", "Credentials": {}, "Ad Error": "null" }
iOS
Network: GADMAdapterGoogleAdMobAds Ad Source Name: Reservation campaign Ad Source ID: 7068401028668408324 Ad Source Instance Name: [DO NOT EDIT] Publisher Test Interstitial Ad Source Instance ID: [DO NOT EDIT] Publisher Test Interstitial AdUnitMapping: { } Error: (null) Latency: 0.391
对于每个广告联盟,AdapterResponseInfo 都提供以下方法:
| 方法 | 说明 | 
|---|---|
| AdError | 获取与向广告联盟发送的广告请求相关的错误。如果广告联盟成功加载广告或未尝试加载广告,则返回 null。 | 
| AdSourceId | 获取与此适配器响应相关联的广告来源 ID。对于广告系列,系统会针对“参与中介的广告”广告系列目标类型返回 6060308706800320801,并针对展示次数和点击次数目标类型返回7068401028668408324。如需查看广告联盟投放广告时可用的广告来源 ID 的列表,请参阅广告来源。 | 
| AdSourceInstanceId | 获取与此适配器响应相关联的广告来源实例 ID。 | 
| AdSourceInstanceName | 获取与此适配器响应相关联的广告来源实例名称。 | 
| AdSourceName | 获取代表可提供展示机会的特定广告联盟的广告来源。对于广告系列,系统会针对“参与中介的广告”广告系列目标类型返回 Mediated House Ads,并针对展示次数和点击次数目标类型返回Reservation Campaign。如需查看广告联盟投放广告时可用的广告来源名称的列表,请参阅广告来源。 | 
| AdapterClassName | 获取用于标识广告联盟的类名称。 | 
| AdUnitMapping | 获取在 AdMob 界面中设置的广告联盟配置。 | 
| LatencyMillis | 获取广告联盟加载广告所用的时间。如果广告联盟未尝试加载广告,则返回 0。 | 
以下示例展示了如何从加载的 AdapterResponseInfo 读取值:
private void LoadInterstitialAd()
{
  AdRequest adRequest = new AdRequest();
  InterstitialAd.Load("AD_UNIT_ID", adRequest, (InterstitialAd insterstitialAd, LoadAdError error) =>
  {
    // If the operation failed with a reason.
    if (error != null)
    {
        Debug.LogError("Interstitial ad failed to load an ad with error : " + error);
        return;
    }
    ResponseInfo responseInfo = insterstitialAd.GetResponseInfo();
    AdapterResponseInfo loadedAdapterResponseInfo = responseInfo.getLoadedAdapterResponseInfo();
    AdError adError = loadedAdapterResponseInfo.AdError;
    string adSourceId = loadedAdapterResponseInfo.AdSourceId;
    string adSourceInstanceId = loadedAdapterResponseInfo.AdSourceInstanceId;
    string adSourceInstanceName = loadedAdapterResponseInfo.AdSourceInstanceName;
    string adSourceName = loadedAdapterResponseInfo.AdSourceName;
    string adapterClassName = loadedAdapterResponseInfo.AdapterClassName;
    Dictionary<string, string> credentials = loadedAdapterResponseInfo.AdUnitMapping;
    long latencyMillis = loadedAdapterResponseInfo.LatencyMillis;
  });
}