出于调试和日志记录目的,成功加载的广告会提供 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;
});
}