This guide shows you how to use GMA Next-Gen SDK to load and display ads from
PubMatic using [AdMob Mediation](https://developers.google.com/admob/android/next-gen/mediation.md.txt), covering both
waterfall and bidding integrations. It covers how to add
PubMatic OpenWrap SDK to an ad unit's mediation
configuration, and how to integrate the
PubMatic OpenWrap SDK and adapter into an
Android app.

## Supported integrations and ad formats

The mediation adapter for PubMatic has the following capabilities:

| Integration ||
|---|---|
| Bidding | Yes |
| Waterfall | Yes [^1^](https://developers.google.com/admob/android/next-gen/mediation/pubmatic.md.txt#waterfall-footnote) |
| App open |   |
| Banner | Yes |
| Interstitial | Yes |
| Rewarded | Yes |
| Rewarded Interstitial |   |
| Native | Yes |

^1^ Waterfall integration is in
alpha.

## Prerequisites

Before you continue, verify the following:

- Android API level 24 or later.

<!-- -->

- Latest GMA Next-Gen SDK version.

- [Set up AdMob Mediation](https://developers.google.com/admob/android/next-gen/mediation.md.txt).

## Step 1: Set up configurations in PubMatic UI

[Sign up](https://go.pubmatic.com/openwrap-sdk-capture-more-direct-brand-spend) or
[Log in](https://apps.pubmatic.com/login/publisher) to your PubMatic account and
select the **OpenWrap SDK** card.

### Add a new application

Navigate to the **Apps** tab and click the **Add App** button.

![Apps Dashboard](https://developers.google.com/static/admob/images/mediation/pubmatic/dashboard_apps.png)

Select the **Platform** , as well as the **App Store URL** and **App Name** for
your app.

Under **Integration Path** , select

**Android (Java / Kotlin)**

and select **AdMob - SDK Bidding** as the **Sub-integration Path** . Then, click
the **Add App** button.

![New App Form](https://developers.google.com/static/admob/images/mediation/pubmatic/new_app_Android.png)

### Update your app-ads.txt


[Authorized Sellers for Apps app-ads.txt](https://iabtechlab.com/wp-content/uploads/2019/03/app-ads.txt-v1.0-final-.pdf) is an IAB Tech Lab initiative that helps ensure your
app ad inventory is only sold through channels you've identified as authorized. To prevent a
significant loss in ad revenue, you'll need to implement an `app-ads.txt` file.

If you haven't done so already,

[set up an app-ads.txt file for your app](https://support.google.com/admob/answer/9363762).

Before your app is finalized, you will be presented the appropriate entries to
add to your `app-ads.txt`.

![app-aps.txt](https://developers.google.com/static/admob/images/mediation/pubmatic/update_app_ads_txt.png)

For additional information on how to implement `app-ads.txt` for PubMatic,
see [How to Implement app-ads.txt](https://help.pubmatic.com/publisher/docs/app-adstxt-adstxt-for-apps-overview#how-to-implement-app-adstxt).

#### Profile ID

Once your app is created, navigate to the **Apps** tab and take note of your
newly created application's **Profile ID**.

![App Profile ID](https://developers.google.com/static/admob/images/mediation/pubmatic/app_details_profile_id.png)

### Create an ad unit

Under the **Ad Units** tab, select the app you created on the previous section
and click the **Create Ad Unit** button.

![Create Ad Unit](https://developers.google.com/static/admob/images/mediation/pubmatic/create_ad_unit.png)

Fill out the form with the details of your ad unit and click **Save**.

![Create Ad Unit Form](https://developers.google.com/static/admob/images/mediation/pubmatic/create_ad_unit_form.png)

Take note of your newly created **OpenWrap Ad Unit ID**.

![App Ad Unit ID](https://developers.google.com/static/admob/images/mediation/pubmatic/app_details_ad_unit.png)

### Obtain your Publisher ID

Navigate to the [Analytics Dashboard](https://apps.pubmatic.com/v3/analytics/dashboard).
Hover over the profile icon and take note of your **ID**.

![Publisher ID](https://developers.google.com/static/admob/images/mediation/pubmatic/publisher_id.png)

## Step 2: Set up PubMatic demand in AdMob UI

### Configure mediation settings for your ad unit

You need to add PubMatic OpenWrap SDK to the
mediation configuration for your ad unit.

First, sign in to your [AdMob account](https://apps.admob.com/). Next, navigate to the
**Mediation** tab. If you have an existing mediation group you'd like to modify,
click the name of that mediation group to edit it, and skip ahead to
[Add PubMatic OpenWrap SDK as an ad source](https://developers.google.com/admob/android/next-gen/mediation/pubmatic.md.txt#add-ad-source).

To create a new mediation group, select **Create Mediation Group**.

![](https://developers.google.com/static/admob/images/mediation/admob-mediation-group-create.png)

Enter your ad format and platform, then click **Continue**.

![](https://developers.google.com/static/admob/images/mediation/admob-mediation-group-new-Android.png)

Give your mediation group a name, and select locations to target. Next, set the
mediation group status to **Enabled** , and then click **Add Ad Units**.

![](https://developers.google.com/static/admob/images/mediation/admob-mediation-group-details-Android.png)

Associate this mediation group with one or more of your existing
AdMob ad units. Then click **Done**.

![](https://developers.google.com/static/admob/images/mediation/admob-ad-units-select-Android.png)

You should now see the ad units card populated with the ad units you selected:

![](https://developers.google.com/static/admob/images/mediation/admob-ad-units-card-Android.png)

### Add PubMatic OpenWrap SDK as an ad source

### Bidding

<br />

In the **Ad Sources** section, find the **Bidding** card and select **Add
ad source** . Then select **PubMatic OpenWrap SDK** .  

Click **Acknowledge \& agree** and then click **Save** .  

![](https://developers.google.com/static/admob/images/mediation/pubmatic/bidding-agreement.png)   

If you already have a mapping for PubMatic OpenWrap SDK, you can select it. Otherwise, click **Add mapping** .   

![](https://developers.google.com/static/admob/images/mediation/pubmatic/bidding-add-mapping-1-Android.png)   

Next, enter the **OpenWrap Ad Unit ID** obtained in the previous section. Then click **Done** .   

**Important** : The **OpenWrap Publisher ID** and **OpenWrap Profile ID** must be associated with the targeted app as in the PubMatic OpenWrap SDK UI.   

![](https://developers.google.com/static/admob/images/mediation/pubmatic/bidding-add-mapping-2-Android.png)

### Waterfall

<br />

Under the **Waterfall** card in the **Ad Sources** section, select **Add Ad
Source** .  

Select **PubMatic OpenWrap SDK** . Then enter an **eCPM value** for PubMatic OpenWrap SDK and click **Continue** .  

![](https://developers.google.com/static/admob/images/mediation/pubmatic/admob-add-ad-network.png)  

> [!NOTE]
> **Note**: You only need to set up ad source optimization once per network.

<br />

If you already have a mapping for PubMatic OpenWrap SDK, you can select it. Otherwise, click **Add mapping** .  

![](https://developers.google.com/static/admob/images/mediation/pubmatic/waterfall-add-mapping-1-Android.png)  

Next, enter the **OpenWrap Ad Unit ID** obtained in the previous section. Then click **Done** .  
**Important** : The **OpenWrap Publisher ID** and **OpenWrap Profile ID** must be associated with the targeted app as in the PubMatic OpenWrap SDK UI.   
![](https://developers.google.com/static/admob/images/mediation/pubmatic/waterfall-add-mapping-2-Android.png)  

### Add PubMatic to GDPR and US state regulations ad partners list

> [!IMPORTANT]
> **Important:** Verify that you have **Account Management** permission to complete the configuration for EU Consent and GDPR, US State regulations, and User Messaging Platform. See [Manage user access to your
> account](https://support.google.com/admob/answer/2784628) for details.

Follow the steps in

[European regulations settings](https://support.google.com/admob/answer/10113004#adding_ad_partners_to_published_gdpr_messages)

and

[US state regulations settings](https://support.google.com/admob/answer/14125907)


to add **PubMatic** to the
European and US state regulations ad partners list in the AdMob UI.


## Step 3: Import the PubMatic OpenWrap SDK and adapter

> [!NOTE]
> **Note:** Failure to integrate the compatible PubMatic OpenWrap SDK and Google Mobile Ads SDK versions might lead to build issues.

### Android Studio integration (recommended)

In your project-level `settings.gradle.kts` file, add the following
repositories:

```kotlin
dependencyResolutionManagement {
  repositories {
    google()
    mavenCentral()
    maven {
url = uri("https://repo.pubmatic.com/artifactory/public-repos")
}
  }
}
```

Then, in your app-level `build.gradle.kts` file, add the following
implementation dependencies and configurations. Use the latest versions of the
PubMatic OpenWrap SDK SDK and adapter:

```kotlin
dependencies {
    implementation("com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:1.6.0")
    implementation("com.google.ads.mediation:pubmatic:5.4.1.0")
}

configurations {
    all {
exclude(group = "com.google.android.gms", module = "play-services-ads")
exclude(group = "com.google.android.gms", module = "play-services-ads-lite")
}
}
```

## Step 4: Implement privacy settings on PubMatic


To [comply with
the Google EU User Consent Policy](https://www.google.com/about/company/consentstaging.html), you must make certain disclosures to your
users in the European Economic Area (EEA), the UK, and Switzerland, and obtain
their consent for the use of cookies or other local storage where legally
required, and for the collection, sharing, and use of personal data for ads
personalization. This policy reflects the requirements of the EU ePrivacy
Directive and the General Data Protection Regulation (GDPR). You are
responsible for verifying that consent is propagated to each ad source in your
mediation chain.

PubMatic OpenWrap SDK Android adapter version
4.7.0.0
and later supports passing GDPR consent signals from consent management
platforms that integrate with IAB's Transparency and Consent Framework (TCF)
to PubMatic OpenWrap SDK SDK.
For more information, see

[Pass GDPR and GDPR consent](https://help.pubmatic.com/openwrap/reference/advanced-topics-1#pass-gdpr-and-gdpr-consent).


### US states privacy laws


[US states privacy laws](https://support.google.com/admob/answer/9561022)
require giving users the right
to opt out of the "sale" of their "personal information" (as the law defines
those terms), with the opt-out offered through a prominent "Do Not Sell My Personal
Information" link on the "selling" party's homepage. The
[US states privacy
laws compliance guide](https://developers.google.com/admob/android/next-gen/privacy/us-states) offers the ability to enable
[restricted data processing](https://privacy.google.com/businesses/rdp/)
for Google ad serving, but Google is unable to apply this setting to each ad
network in your mediation chain. Therefore, you must identify each ad network
in your mediation chain that may participate in the sale of personal
information and follow guidance from each of those networks to ensure
compliance.

PubMatic automatically reads GPP consent set by consent management
platforms that support

[Google's Additional Consent specification](https://support.google.com/admob/answer/9681920),

including the

[UMP SDK](https://developers.google.com/admob/android/privacy.md.txt).

For more information, see

[Pass GPP consent](https://help.pubmatic.com/openwrap/reference/advanced-topics-1#pass-gpp-consent).


## Step 5: Add required code

No additional code needed for PubMatic OpenWrap SDK integration.

## Step 6: Test your implementation

### Enable test ads

Make sure you
[register your test device](https://developers.google.com/admob/android/next-gen/test-ads.md.txt#enable_test_devices)
for

AdMob.


> [!IMPORTANT]
> **Important:** Disable test mode for AdMob and PubMatic OpenWrap SDK before releasing your app.

### Verify test ads

To verify that you are receiving test ads from
PubMatic OpenWrap SDK,
enable
[single ad source testing](https://developers.google.com/admob/android/next-gen/ad-inspector.md.txt#single_ad_source_testing)
in ad inspector using the
**PubMatic OpenWrap** ad source(s).

## Optional Steps

### Native ads

#### Ad rendering

The PubMatic adapter returns its native ads as

`NativeAd`

objects. It populates the following

[fields](https://support.google.com/admob/answer/6240809)

for a

[`NativeAd`](https://developers.google.com/admob/android/next-gen/reference/com/google/android/libraries/ads/mobile/sdk/nativead/NativeAd.md.txt).


| Field | Assets always included by PubMatic adapter |
|---|---|
| Headline | Yes |
| Image | Yes |
| Body | Yes |
| Icon | Yes |
| Call to action | Yes |
| Star rating | Yes |
| Store |   |
| Price | Yes |
| Advertiser | Yes |

## Error codes

If the adapter fails to receive an ad from PubMatic, you can check the
underlying error from the ad response using


[`ResponseInfo.getAdSourceResponses()`](https://developers.google.com/admob/android/next-gen/reference/com/google/android/libraries/ads/mobile/sdk/common/ResponseInfo.md.txt#getAdSourceResponses())

under the following classes:

```java
com.pubmatic.sdk
com.google.ads.mediation.pubmatic
```

Here are the codes and accompanying messages thrown by the PubMatic adapter
when an ad fails to load:

| Error code | Domain | Reason |
|---|---|---|
| 101 | com.google.ads.mediation.pubmatic | Server configuration missing a required publisher ID. |
| 102 | com.google.ads.mediation.pubmatic | Ad format unsupported by PubMatic or missing in RTB signal data. |
| 103 | com.google.ads.mediation.pubmatic | Failed to present an ad because the ad was not ready. |
| 104 | com.google.ads.mediation.pubmatic | Missing or invalid Profile ID. |
| 105 | com.google.ads.mediation.pubmatic | Missing or empty Ad Unit ID. |
| 106 | com.google.ads.mediation.pubmatic | Returned Rewarded ad is null. |
| 107 | com.google.ads.mediation.pubmatic | Invalid banner ad size. |
| 1001-5002 | Sent by PubMatic SDK | PubMatic SDK returned an error. See PubMatic's [documentation](https://pubmatic-sdk.s3.amazonaws.com/androidapidoc/html/com/pubmatic/sdk/common/POBError.html) for more details. |

## PubMatic Android Mediation Adapter Changelog

#### Version 5.5.0.0 (In progress)

- Updated the adapter to use the `InitializationCompleteCallback.onInitializationFailed(AdError)` API.

#### Version 5.4.1.0

- Updated the minimum required Android API level to 24.
- Verified compatibility with Pubmatic SDK 5.4.1.

Built and tested with:

- Google Mobile Ads SDK version 25.5.0.
- Google Mobile Ads Next-Gen SDK version 1.5.0.
- Pubmatic SDK version 5.4.1

#### Version 5.4.0.0

- Verified compatibility with Pubmatic SDK 5.4.0.

Built and tested with:

- Google Mobile Ads SDK version 25.4.0.
- Google Mobile Ads Next-Gen SDK version 1.4.0.
- Pubmatic SDK version 5.4.0

#### Version 5.3.0.1

- Pin the adapter's Kotlin dependency to 1.9.0 (the min Kotlin version supported by GMA NextGen SDK).

Built and tested with:

- Google Mobile Ads SDK version 25.4.0.
- Google Mobile Ads Next-Gen SDK version 1.4.0.
- Pubmatic SDK version 5.3.0

#### Version 5.3.0.0

- Verified compatibility with Pubmatic SDK 5.3.0.

Built and tested with:

- Google Mobile Ads SDK version 25.4.0.
- Google Mobile Ads Next-Gen SDK version 1.4.0.
- Pubmatic SDK version 5.3.0

#### Version 5.2.0.0

- Verified compatibility with Pubmatic SDK 5.2.0.

Built and tested with:

- Google Mobile Ads SDK version 25.4.0.
- Google Mobile Ads Next-Gen SDK version 1.3.0.
- Pubmatic SDK version 5.2.0

#### Version 5.1.2.2

- Maps `AgeRestrictedTreatment` to PubMatic's COPPA API.

Built and tested with:

- Google Mobile Ads SDK version 25.4.0.
- Google Mobile Ads Next-Gen SDK version 1.2.1.
- Pubmatic SDK version 5.1.2

#### Version 5.1.2.1

- Added native ad video(VAST) support using PubMatic OpenWrapSDK MediaView API.

Built and tested with:

- Google Mobile Ads SDK version 25.2.0.
- Google Mobile Ads Next-Gen SDK version 1.2.1.
- Pubmatic SDK version 5.1.2

#### Version 5.1.2.0

- Verified compatibility with Pubmatic SDK 5.1.2.

Built and tested with:

- Google Mobile Ads SDK version 25.2.0.
- Google Mobile Ads Next-Gen SDK version 1.1.0.
- Pubmatic SDK version 5.1.2

#### Version 5.1.1.0

- Verified compatibility with Pubmatic SDK 5.1.1.

Built and tested with:

- Google Mobile Ads SDK version 25.2.0.
- Google Mobile Ads Next-Gen SDK version 1.0.1.
- Pubmatic SDK version 5.1.1

#### Version 5.1.0.0

- Verified compatibility with Pubmatic SDK 5.1.0.

Built and tested with:

- Google Mobile Ads SDK version 25.2.0.
- Pubmatic SDK version 5.1.0

#### Version 5.0.0.1

- Added property to build the adapter with GMA Next-Gen SDK dependency.
- Fixed a bug where the `mediationUtils` object wasn't being initialized.

Built and tested with:

- Google Mobile Ads SDK version 25.1.0.
- Pubmatic SDK version 5.0.0

#### Version 5.0.0.0

- Verified compatibility with Pubmatic SDK 5.0.0.

Built and tested with:

- Google Mobile Ads SDK version 25.0.0.
- Pubmatic SDK version 5.0.0

#### Version 4.12.0.0

- Verified compatibility with Pubmatic SDK 4.12.0.

Built and tested with:

- Google Mobile Ads SDK version 24.9.0.
- Pubmatic SDK version 4.12.0

#### Version 4.11.0.1

- Added support for forwarding the `tagForUnderAgeOfConsent` Google Mobile Ads SDK parameter to the PubMatic SDK.

Built and tested with:

- Google Mobile Ads SDK version 24.9.0.
- Pubmatic SDK version 4.11.0

#### Version 4.11.0.0

- Verified compatibility with Pubmatic SDK 4.11.0.

Built and tested with:

- Google Mobile Ads SDK version 24.9.0.
- Pubmatic SDK version 4.11.0

#### Version 4.10.0.1

- Added list of assets for waterfall native ad format.

Built and tested with:

- Google Mobile Ads SDK version 24.7.0.
- Pubmatic SDK version 4.10.0

#### Version 4.10.0.0

- Verified compatibility with Pubmatic SDK 4.10.0.

Built and tested with:

- Google Mobile Ads SDK version 24.7.0.
- Pubmatic SDK version 4.10.0

#### Version 4.9.1.0

- Verified compatibility with Pubmatic SDK 4.9.1.

Built and tested with:

- Google Mobile Ads SDK version 24.6.0.
- Pubmatic SDK version 4.9.1

#### Version 4.8.0.1

- Adds support for waterfall interstitial ads.
- Adds support for waterfall rewarded ads.
- Adds support for waterfall banner ads.
- Adds support for waterfall native ads.
- Verified compatibility with Pubmatic SDK 4.8.0.

Built and tested with:

- Google Mobile Ads SDK version 24.6.0.
- Pubmatic SDK version 4.8.0

#### Version 4.8.0.0

- Verified compatibility with Pubmatic SDK 4.8.0.

Built and tested with:

- Google Mobile Ads SDK version 24.4.0.
- Pubmatic SDK version 4.8.0.

#### Version 4.7.1.1

- Fixed size of AdChoices Icon

Built and tested with:

- Google Mobile Ads SDK version 24.4.0.
- Pubmatic SDK version 4.7.1.

#### Version 4.7.1.0

- Verified compatibility with Pubmatic SDK 4.7.1.

Built and tested with:

- Google Mobile Ads SDK version 24.4.0.
- Pubmatic SDK version 4.7.1.

#### Version 4.7.0.1

- Fixed internal dependencies.

Built and tested with:

- Google Mobile Ads SDK version 24.4.0.
- Pubmatic SDK version 4.7.0.

#### Version 4.7.0.0

- Initial release.
- Added bidding support for banner, interstitial, rewarded and native ad formats.
- Verified compatibility with Pubmatic SDK 4.7.0.

Built and tested with:

- Google Mobile Ads SDK version 24.4.0.
- Pubmatic SDK version 4.7.0.