導入鍵/值區隔

您可以使用鍵/值區隔,透過廣告請求定義自訂指定目標,藉此區隔使用者。如要進一步瞭解鍵/值區隔,例如在 AdMob 使用者介面中新增鍵/值組合,請參閱「將鍵/值區隔加進中介服務群組」。

本頁說明如何使用 Google Mobile Ads Unity SDK 設定廣告請求時,導入鍵/值區隔。

事前準備

如要在應用程式中設定鍵/值區隔,請先將鍵/值區隔加進中介服務群組

將鍵/值組合附加至廣告請求

在 AdMob 使用者介面設定自訂鍵/值組合後,請將這些組合附加至應用程式中的廣告請求。

  1. 建立代表自訂指定目標資料的鍵/值組合物件。

  2. 將廣告請求的 CustomTargeting 屬性設為這個物件。

以下範例涵蓋先前步驟,可依應用程式中的時間長度區隔使用者:

var daysInApp = 1;

// Step 1: Create the key-value pair dictionary with custom targeting data.
var customTargeting = new Dictionary<string, string> {
  ["USER_DURATION"] = daysInApp < 3 ? "NEW" : "MATURE",
};

// Step 2: Create an ad request with custom targeting.
var request = new AdRequest() {
  CustomTargeting = customTargeting,
};

測試鍵/值區隔設定

如要測試自訂鍵/值組合的導入作業,請傳送廣告請求並檢查回應資訊物件。確認 mediation_group_name 欄位的值與預期的中介服務群組名稱相符。

以下範例會驗證廣告回應中的中介服務群組名稱:

{
  "Response ID": "r6_DZtitA8Gi2OMPyKeksAI",
  ...
  "Response Extras": {
    "mediation_group_name": "Mediation group for new users"
  }
}