Implement key-value segmentation

  • Key-value segmentation is currently in limited access and requires reaching out to your Google account manager.

  • Key-value segmentation allows you to define custom targeting through ad requests to segment users.

  • To implement key-value segmentation in your app, you must first add key-value segmentation to a mediation group in the AdMob UI.

  • You can attach custom key-value pairs to an ad request by creating a key-value pair object and setting the customTargeting property of the ad request.

  • You can test your key-value segmentation setup by sending an ad request and checking the mediation_group_name field in the response info object.

Key-value segmentation lets you define custom targeting to segment users through an ad request. For details on key-value segmentation, such as adding a key-value pair in the AdMob UI, see Add key-value segmentation to a mediation group.

This page guides you through implementing key-value segmentation when configuring an ad request using the Google Mobile Ads iOS SDK.

Before you begin

To set up key-value segmentation in your app, you must first add key-value segmentation to a mediation group.

Attach key-value pairs to an ad request

After setting up your custom key-value pairs in the AdMob UI, attach the pairs to an ad request in your application.

  1. Create a key-value pair object representing your custom targeting data.

  2. Set the customTargeting property of the ad request to this object.

The following example covers the previous steps to segment users by by duration in an app:

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;

Test the key-value segmentation setup

To test your implementation on custom key-value pairs, send an ad request and check the response info object. Verify the value of the mediation_group_name field matches your expected mediation group name.

The following example verifies a mediation group name in the ad response:

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