# Configure Mediation

## Test Mode

The Mediation SDK includes a **Test Mode** method that will allow you to test your partner integrations and get their test ads. To enable **Test Mode**, your app must be built in debug mode, then set the following method to `true` after starting the Mediation SDK. Remember to remove it or set the method to `false` before releasing your app.

```kotlin
ChartboostMediationSdk.setTestMode(context, true)
ChartboostMediationSdk.setTestMode(context, false)
```


## Keywords

Keywords are key-value pairs to enable real-time targeting of line items.

### Set Keywords

To set keywords, you will need to first create a Mediation ad object. Then, use the `set()` method to add key-value keywords pair. The set method returns a boolean indicating whether or not the keyword has been successfully set.

For `ChartboostMediationFullscreenAd`
```kotlin
// Adding Keywords to the Keywords object
val keywords = Keywords()
keywords["keyword1"] = "value1"

// Passing keywords to the fullscreen load request.
val request = ChartboostMediationFullscreenAdLoadRequest(
    placement = "placement",
    keywords = keywords,
)

val result =
    ChartboostMediationFullscreenAd.loadFullscreenAd(
        context,
        request,
        listener,
    )

// Adding Keywords from the ad result.
result.ad?.request?.keywords?.set("keyword1", "value1")
```

For `Banners`
```kotlin
// Adding Keywords to the Keywords object.
val keywords = Keywords()
keywords["banner1"] = "value1"

val bannerRequest = ChartboostMediationBannerAdLoadRequest(
    "placement",
    keywords,
    bannerSize,
)

// Adding Keywords to banner request.
bannerRequest.keywords["banner2"] = "value2"
```

### Remove Keywords

To remove keywords that have been set, simply use the `remove()` method and pass in the key whose value you would like to remove. The remove method returns the value of the key removed.

For `ChartboostMediationFullscreenAd`
```kotlin
// Removing Keywords.
keywords.remove("keyword1")
```

For `Banners`

```kotlin
val bannerAdView = ChartboostMediationBannerAdView(
    context,
    "placement",
    size,
    listener,
)
// Removing a keyword from the banner ad view
bannerAdView.keywords.remove("key1")

// It is also possible to remove the keyword from the banner load request
val keywords = Keywords()
keywords["key1"] = "value1"
keywords.remove("key1")
val loadRequest = ChartboostMediationBannerAdLoadRequest("placement", keywords, size)
// Can then load the banner with the keywords
bannerAdView.load(loadRequest)
```

<div class="alert alert-info" role="alert">
  <b>Note:</b> The keywords API has restrictions for setting keys and values. The maximum number of characters allowed for each key name is 64 characters. For values, it is 256 characters.
</div>





## Impression Level Revenue Data (ILRD)

Impression Level Revenue Data (ILRD) is data we already collect on the server side and store in our database today. This feature allows publishers to get access to this data.

An ILRD event occurs every time an impression is tracked. The fields that a publisher is interested in are broken down as follows:

| ILRD Key                 |  Value | ILRD Description                                                                                        |
| :----------------------- | :----: | :------------------------------------------------------------------------------------------------------ |
| `"ad_revenue"`           | Double | Double-precision floating point                                                                         |
| `"currency_type"`        | String | Always USD                                                                                              |
| `"country"`              | String | Three-letter country code ISO_3166-1_alpha-3 (ex. "USA")                                                |
| `"impression_id"`        | String | ID                                                                                                      |
| `"line_item_name"`       | String | Mediation line item name                                                                                |
| `"line_item_id"`         | String | Mediation line item id                                                                                  |
| `"network_name"`         | String | Network Name                                                                                            |
| `"network_placement_id"` | String | Partner placement name                                                                                  |
| `"network_type"`         | String | Either `bidding` or `mediation`                                                                         |
| `"placement_name"`       | String | Mediation placement name                                                                                |
| `"placement_type"`       | String | Ad type: <br/>- `interstitial`<br/>- `rewarded`<br/>- `banner`                                          |
| `"precision"`            | String | One of the following: <br/>- `estimated` <br/>- `exact` <br/>- `publisher_defined` <br/>- `undisclosed` |

### Bid Specific ILRD
```json
{
 "network_name": "chartboost",
 "network_type": "bidding",
 "precision": "exact",
 "ad_revenue": 0.099,
 "network_placement_id": "CBRewarded"
}
```

### Ad Response ILRD
```json
{
 "impression_id": "7e4c99a9492c75f3b5fcbb4da8cd8e040794c4fe",
 "currency_type": "USD",
 "country": "USA",
 "placement_name": "CBRewarded",
 "placement_type": "rewarded"
}
```

### Combined ILRD Response
```json
{
 "ad_revenue": 0.055,
 "currency_type": "USD",
 "country": "USA",
 "impression_id": "ae112f3dccf90c705f2d3b1324605e9d16687725",
 "line_item_name": "helium_rv_T1_mintegral_high",
 "line_item_id": "33f6b0ca-1b3c-4e69-80dd-b57db13db159",
 "network_name": "mintegral",
 "network_placement_id": "mintegral_RV_0_25",
 "network_type": "mediation",
 "placement_name": "heliumMintegralTest",
 "placement_type": "rewarded",
 "precision": "publisher_defined"
}
```

Publishers can receive ILRD data in two ways:

1. On Android, we provide a global notification that gives publishers access to ILRD data on each impression event shown in real time.
2. For API access, we can provide an ILRD reporting API where publishers can request a custom report (CSV) of all their ILRD data filtered by `appId`, `min_date`, `max_date`.

Publishers can use ILRD data in several ways:

- You can listen to the data via SDK notifications in real-time and ship it to your own servers or to other MMPs such as AppsFlyer or Adjust.
- You can manually request a report via the API endpoint and analyze it at your convenience.

<div class="alert alert-info" role="alert">
  <b>Meta Audience Network Ad Revenue</b><br>
  <li>Unlike other networks, Meta prohibits Mediation from sharing the real `ad_revenue` value of Meta Audience Network impressions with publishers.</li>
  <li>Instead, Mediation is only allowed to share the average of aggregated eCPMs of Meta Audience Network line items.</li>
</div>



## Rewarded Callbacks

Setting the User ID and Custom Data through the SDK.

### Setting User Identifier

The user identifier property is configured with the [Chartboost Core SDK](/en/mediation/integrate/core/android/).

```kotlin
ChartboostCore.publisherMetadata.setPlayerIdentifier("player_id")
```

### Setting Custom Data

The custom data property is found on the `ChartboostMediationFullscreenAd` instance, and has a maximum character limit of 1000 characters. In the event that the limit is exceeded, the `customData` property will be set to `null`. 

Custom data may be set at any time before calling `show()`.

**It is recommended to base 64 encode the custom data!**

```kotlin
// Load an ad
val result =
    ChartboostMediationFullscreenAd.loadFullscreenAd(
        context,
        request,
        listener,
    )

// Set Custom Data
result.ad?.customData = "Y3VzdG9tIGRhdGE="
```

**See**: [Mediation SDK: Manage Placement's Rewarded Callbacks](/en/mediation/manage-placements/#rewarded-callbacks) for configuration setup



## Implementation

Create a `ChartboostMediationIlrdObserver` object and implement its `onImpression` method. Then, pass the object to the `ChartboostMediationSdk.subscribeIlrd` and `ChartboostMediationSdk.unsubscribeIlrd` methods.

```kotlin
val chartboostMediationIlrdObserver = object: ChartboostMediationIlrdObserver {
  override fun onImpression(impData: ChartboostMediationImpressionData) {
      // Placement name
      val placement = impData.placementId
      // JSON
      val json = impData.ilrdInfo
  }
}

override fun onCreate(savedInstanceState: Bundle?) {
  ...
  // Subscribe to ILRD on app startup, e.g. in onCreate()
  ChartboostMediationSdk.subscribeIlrd(chartboostMediationIlrdObserver)
  ...
}

override fun onDestroy() {
  ...
  // Unsubscribe from ILRD on app terminations, e.g. in onDestroy()
  ChartboostMediationSdk.unsubscribeIlrd(chartboostMediationIlrdObserver)
  ...
}
```



