擷取廣告回應的相關資訊

為了進行偵錯和記錄,成功載入的廣告會提供 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 回應 ID 是廣告回應的專屬 ID。這個 ID 可用來在廣告檢閱中心 (ARC) 中找出並封鎖廣告。
GetResponseExtras 傳回廣告回應的額外資訊。額外項目可以傳回下列鍵:
  • mediation_group_name:中介服務群組的名稱
  • mediation_ab_test_name中介服務 A/B 版本測試的名稱 (如適用)
  • mediation_ab_test_variant:中介服務 A/B 版本測試中使用的變化版本 (如果有的話)

以下是從已載入的 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 UI 取得網路設定。
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;
  });
}