Select platform: [Android (beta)
![New-selected](https://developers.google.com/static/admob/images/new-selected.svg)](https://developers.google.com/admob/android/next-gen/mediation/segmentation "View this page for the Android (beta) platform docs.") [Android](https://developers.google.com/admob/android/mediation/segmentation "View this page for the Android platform docs.") [iOS](https://developers.google.com/admob/ios/mediation/segmentation "View this page for the iOS platform docs.") [Unity](https://developers.google.com/admob/unity/mediation/segmentation "View this page for the Unity platform docs.")

<br />

| **Note:** Key-value segmentation is in limited access. Reach out to your Google account manager to request access.

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](https://support.google.com/admob/answer/14916631).

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

## Before you begin

To set up key-value segmentation in your app, you must first
[add key-value segmentation to a mediation group](https://support.google.com/admob/answer/14916631).

## 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.

To attach the key-value pairs to an ad request, call
[`putCustomTargeting()`](https://developers.google.com/admob/android/next-gen/reference/com/google/android/libraries/ads/mobile/sdk/common/AdRequest.Builder#putCustomTargeting(kotlin.String,kotlin.String))
with the key and value.

The following example segments users by duration in an app:  

### Kotlin

    val daysInApp = 1
    val request = AdRequest.Builder("<var class="readonly" translate="no">AD_UNIT_ID</var>")
      .putCustomTargeting("USER_DURATION", if (daysInApp < 3) "NEW" else "MATURE")
      .build()

### Java

    int daysInApp = 1;
    AdRequest request = new AdRequest.Builder("<var class="readonly" translate="no">AD_UNIT_ID</var>")
        .putCustomTargeting("USER_DURATION", (daysInApp < 3) ? "NEW" : "MATURE")
        .build();

## Test the key-value segmentation setup

To test your implementation on custom key-value pairs, send an ad request and
check the [response info](https://developers.google.com/admob/android/next-gen/response-info#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"
      }
    }