Key-Value セグメンテーションを実装する

Key-Value セグメンテーションを使用すると、広告リクエストを通じてユーザーをセグメント化するカスタム ターゲティングを定義できます。AdMob の管理画面で Key-Value ペアを追加するなど、Key-Value セグメンテーションの詳細については、 メディエーション グループに Key-Value セグメンテーションを追加するをご覧ください。

このページでは、Google Mobile Ads iOS SDK を使用して広告リクエストを設定する際に、Key-Value セグメンテーションを実装する方法について説明します。

始める前に

アプリで Key-Value セグメンテーションを設定するには、まず メディエーション グループに Key-Value セグメンテーションを追加する必要があります。

Key-Value ペアを広告リクエストに関連付ける

AdMob の管理画面でカスタム Key-Value ペアを設定したら、アプリの広告リクエストにペアを関連付けます。

  1. カスタム ターゲティング データを表す Key-Value ペア オブジェクトを作成します。

  2. 広告リクエストの customTargeting プロパティをこのオブジェクトに設定します。

次の例では、アプリで期間ごとにユーザーをセグメント化する手順について説明します。

Swift

let daysInApp = 1

// Step 1: Create the key-value pair dictionary with custom targeting data.
let customTargeting: [String: String] = [
  "USER_DURATION": daysInApp < 3 ? "NEW" : "MATURE"
]

// Step 2: Create an ad request with custom targeting.
let request = GADRequest()
request.customTargeting = customTargeting

Objective-C

int days_in_app = 1;

// Step 1: Create the key-value pair object with custom targeting data.
NSDictionary *customTargeting = @{
  @"USER_DURATION" : days_in_app < 3 ? @"NEW" : @"MATURE"
};

// Step 2: Create an ad request with custom targeting.
GADRequest *request = [GADRequest request];
request.customTargeting = customTargeting;

Key-Value セグメンテーションの設定をテストする

カスタム Key-Value ペアの実装をテストするには、広告リクエストを送信して レスポンス情報オブジェクトを確認します。mediation_group_name フィールドの値が、想定されるメディエーション グループ名と一致していることを確認します。

次の例では、広告レスポンスでメディエーション グループ名を確認します。

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