Google Ad Manager and AdMob mediation
- Latest Version: Android release notes
- Sample App: Teads android Sample App
This article shows you how to deliver Teads ads on your application using the AdMob adapter or Google Ad Manager (GAM) Mediation adapter, for the Media, Native Ad, Interstitial, and Banner (Anchored) formats.
Installation
Before installing the Teads AdMob adapter, you will need to integrate GoogleMobileAds SDK into your application.
Gradle
project/build.gradle
allprojects {
repositories {
...
maven { url "https://teads.jfrog.io/artifactory/SDKAndroid-maven-prod" }
}
}
app/build.gradle
dependencies {
...
implementation 'com.google.android.gms:play-services-ads:23.6.0' // or higher
// Teads inApp SDK
implementation("tv.teads.sdk.android:sdk:6.2.0@aar") {
transitive = true
}
// Teads Admob Adapter
implementation 'tv.teads.sdk.android:admobadapter:6.2.0'
}
- Media
- Native Ad
- Interstitial
- Banner
Prerequisites
- Import the Teads inApp SDK in your project.
- GoogleMobileAds SDK: 20+
Defining a Custom Event
In order to display a Teads ad using AdMob or Google Ad Manager mediation, you need to create a custom event.
Admob
Follow the custom event documentation on the AdMob dashboard using the below values.
| Name | Value |
|---|---|
| Class Name | tv.teads.adapter.admob.TeadsAdapter |
| Parameter | Teads placement ID (PID) |
Google Ad Manager
Follow the custom event documentation on Google Ad Manager using the below values.
| Name | Value |
|---|---|
| Class Name | tv.teads.adapter.admob.TeadsAdapter |
| Parameter | Teads placement ID (PID) |
Please retrieve your production PID from your local account manager.
See this page for test PIDs and creative formats.
Ad Resizing
The code below must be implemented to enable the resizing of the mediated ad slot making possible the rendering of square and vertical creatives.
Initialize the TeadsHelper first.
- Kotlin
- Java
TeadsHelper.initialize()
TeadsHelper.initialize();
You can instantiate a new listener as below, the listener needs to be a class member field or strong referenced somewhere, we keep internally a weak reference to it, so it goes garbage collected when you don't need it anymore:
- Kotlin
- Java
listener = object : TeadsAdapterListener {
override fun onRatioUpdated(adRatio: AdRatio) {
val params: ViewGroup.LayoutParams = adView.layoutParams
// Here the width is MATCH_PARENT
params.height = adRatio.calculateHeight(adView.measuredWidth)
adView.layoutParams = params
}
override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) {
}
}
listener = new TeadsAdapterListener() {
@Override
public void onRatioUpdated(AdRatio adRatio) {
ViewGroup.LayoutParams params = adView.getLayoutParams();
// Here the width is MATCH_PARENT
params.height = adRatio.calculateHeight(adView.getMeasuredWidth());
adView.setLayoutParams(params);
}
@Override
public void adOpportunityTrackerView(AdOpportunityTrackerView trackerView) {
}
};
Use the helper to attach a listener, it will return you a UNIQUE key to reference the current listener attached.
- Kotlin
- Java
val key = TeadsHelper.attachListener(listener)
int key = TeadsHelper.attachListener(listener);
Finally, add it to your current ad settings for the specific ad request
- Kotlin
- Java
val settings = TeadsMediationSettings.Builder()
.setMediationListenerKey(key)
.build()
val adRequest = AdRequest.Builder()
.addNetworkExtrasBundle(TeadsAdapter::class.java, settings.toBundle())
.build()
TeadsMediationSettings settings = new TeadsMediationSettings.Builder()
.setMediationListenerKey(key)
.build();
AdRequest adRequest = new AdRequest.Builder()
.addNetworkExtrasBundle(TeadsAdapter.class, settings.toBundle())
.build();
Mediation settings
Find the full settings list in the Integration Guide and Settings Configuration
Check list
- ✅ Ensure Brand Safety is enabled
- ✅ Ensure you comply with privacy legal requirements (GDPR/CCPA/GPP)
- ✅ Comply with app-ads.txt
- ✅ Enable ad view resizing
- ✅ Test different PIDs with various ad formats and sizes
- ✅ Enable validation mode to ensure key features are working
- ✅ Implement proper error handling
- ✅ Test on different devices and screen sizes
Prerequisites
- Import the Teads inApp SDK in your project.
- GoogleMobileAds SDK: 20+
Defining a Custom Event
In order to display a Teads ad using AdMob or Google Ad Manager mediation, you need to create a custom event.
Admob
Follow the custom event documentation on the AdMob dashboard using the below values.
| Name | Value |
|---|---|
| Class Name | tv.teads.adapter.admob.nativead.TeadsNativeAdapter |
| Parameter | Teads placement ID (PID) |
Google Ad Manager
Follow the custom event documentation on Google Ad Manager using the below values.
| Name | Value |
|---|---|
| Class Name | tv.teads.adapter.admob.nativead.TeadsNativeAdapter |
| Parameter | Teads placement ID (PID) |
Please retrieve your production PID from your local account manager.
See this page for test PIDs and creative formats.
Display an ad
Create your custom layout
Create a new layout for an ad item with the AdMob container NativeAdView
<com.google.android.gms.ads.nativead.NativeAdView
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/ad_headline"
...
/>
<com.google.android.gms.ads.nativead.MediaView
android:id="@+id/ad_media"
...
/>
...
</com.google.android.gms.ads.nativead.NativeAdView>
Native Ad Elements
headlineView(Guaranteed in every request)mediaView(Guaranteed in every request)bodyViewcallToActionViewiconViewpriceViewstarRatingViewstoreViewadvertiserView
Request an ad
Create the AdLoader
You need to inflate your previously created XML view using LayoutInflater
- Kotlin
- Java
MobileAds.initialize(this)
val adLoader = AdLoader.Builder(this, ADMOB_TEADS_NATIVE_ID)
.forNativeAd { ad: NativeAd ->
adView = layoutInflater.inflate(R.layout.layout_admob_native, null) as NativeAdView
populateUnifiedNativeAdView(ad, adView)
}
.withAdListener(object : AdListener() {
...
// can subscribe to other ad experience events
override fun onAdFailedToLoad(error: LoadAdError) {}
})
.withNativeAdOptions(NativeAdOptions.Builder().build())
.build()
MobileAds.initialize(this);
AdLoader adLoader = new AdLoader.Builder(this, ADMOB_TEADS_NATIVE_ID)
.forNativeAd(ad -> {
adView = (NativeAdView) layoutInflater.inflate(R.layout.layout_admob_native, null);
populateUnifiedNativeAdView(ad, adView);
})
.withAdListener(new AdListener() {
// can subscribe to other ad experience events
@Override
public void onAdFailedToLoad(LoadAdError error) {}
})
.withNativeAdOptions(new NativeAdOptions.Builder().build())
.build();
Load an ad
Create the TeadsMediationSettings, then add the settings to the AdRequest using toBundle() method
- Kotlin
- Java
val settings = TeadsMediationSettings.Builder()
.enableDebug()
.build()
val adRequest = AdRequest.Builder()
.addNetworkExtrasBundle(TeadsNativeAdapter::class.java, settings.toBundle())
.build()
adLoader.loadAd(adRequest)
TeadsMediationSettings settings = new TeadsMediationSettings.Builder()
.enableDebug()
.build();
AdRequest adRequest = new AdRequest.Builder()
.addNetworkExtrasBundle(TeadsNativeAdapter.class, settings.toBundle())
.build();
adLoader.loadAd(adRequest);
Populate the ad
We can then populate and customize our NativeAdView according the data we have received
- Kotlin
- Java
private fun populateUnifiedNativeAdView(nativeAd: NativeAd, adView: NativeAdView) {
// Set the media view. Media content will be automatically populated in the media view once
// adView.setNativeAd() is called.
val mediaView: MediaView = adView.findViewById(R.id.ad_media)
adView.mediaView = mediaView
adView.headlineView = adView.findViewById(R.id.ad_headline)
// The headline is guaranteed to be in every UnifiedNativeAd.
(adView.headlineView as TextView).text = nativeAd.headline
// every other assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to
// check before trying to display them
adView.setNativeAd(nativeAd)
// Add the NativeAdView to your main layout inside your container
containerAdView.addView(adView)
}
private void populateUnifiedNativeAdView(NativeAd nativeAd, NativeAdView adView) {
// Set the media view. Media content will be automatically populated in the media view once
// adView.setNativeAd() is called.
MediaView mediaView = adView.findViewById(R.id.ad_media);
adView.setMediaView(mediaView);
adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
// The headline is guaranteed to be in every UnifiedNativeAd.
((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());
// every other assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to
// check before trying to display them
adView.setNativeAd(nativeAd);
// Add the NativeAdView to your main layout inside your container
containerAdView.addView(adView);
}
Mediation settings
Find the full settings list in the Integration Guide and Settings Configuration
Check list
- ✅ Ensure Brand Safety is enabled
- ✅ Ensure you comply with privacy legal requirements (GDPR/CCPA/GPP)
- ✅ Comply with app-ads.txt
- ✅ Enable ad view resizing
- ✅ Test different PIDs with various ad formats and sizes
- ✅ Enable validation mode to ensure key features are working
This page covers AdMob / Google Ad Manager mediation. If you integrate Teads directly (no mediator), see the direct integration guide.
Prerequisites
- Import the Teads inApp SDK in your project.
- GoogleMobileAds SDK: 23.6.0+
Defining a Custom Event
In order to display a Teads interstitial ad using AdMob or Google Ad Manager mediation, you need to create a custom event.
Admob
Follow the custom event documentation on the AdMob dashboard using the below values.
| Name | Value |
|---|---|
| Class Name | tv.teads.adapter.admob.TeadsInterstitialAdapter |
| Parameter | JSON string (see below) |
Google Ad Manager
Follow the custom event documentation on Google Ad Manager using the below values.
| Name | Value |
|---|---|
| Class Name | tv.teads.adapter.admob.TeadsInterstitialAdapter |
| Parameter | JSON string (see below) |
Custom Event Parameter
The parameter must be a JSON string with the following fields:
| Parameter | Type | Required | Description |
|---|---|---|---|
| articleUrl | String | Yes | The URL of the article/page |
| widgetId | String | Yes | Teads widget ID |
| installationKey | String | Yes | Teads installation key |
| pbf | Int | No | Floor price in US dollars. Forwarded to the auction as the placement floor price. |
For testing purposes, use the following:
{"articleUrl":"https://mobile-demo.outbrain.com","widgetId":"INT_MW_1","installationKey":"NANOWDGT01"}
For production, your articleUrl, widgetId, and installationKey will be unique values provided by your product manager. Contact your local account manager to obtain your production parameters.
Integration
Initialize Google Mobile Ads
Initialize the Google Mobile Ads SDK before loading any ads:
- Kotlin
- Java
import com.google.android.gms.ads.MobileAds
// 1. Initialize AdMob
MobileAds.initialize(context)
import com.google.android.gms.ads.MobileAds;
// 1. Initialize AdMob
MobileAds.initialize(context);
Load, Listen and Show
The full integration follows this flow: create an ad request, load the interstitial, set up fullscreen lifecycle callbacks inside onAdLoaded, then show the ad when ready.
Load with an Activity context (the context passed to InterstitialAd.load(...)). Google recommends passing an Activity when initializing ad objects so mediated networks behave consistently, and the Teads interstitial adapter requires it — with an application context the Teads ad fails to load.
- Kotlin
- Java
import com.google.android.gms.ads.AdError
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.FullScreenContentCallback
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
var interstitialAd: InterstitialAd? = null
// 2. Create the AdRequest
val adRequest = AdRequest.Builder().build()
// 3. Load the interstitial ad
InterstitialAd.load(
context,
"YOUR_AD_UNIT_ID", // Ad unit id configured on Google mediation platform
adRequest,
object : InterstitialAdLoadCallback() {
override fun onAdLoaded(ad: InterstitialAd) {
// 4. Listen to fullscreen lifecycle events
ad.fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() {
// Ad is now visible fullscreen
}
override fun onAdDismissedFullScreenContent() {
// Ad was closed by the user
interstitialAd = null
}
override fun onAdFailedToShowFullScreenContent(error: AdError) {
// Ad failed to display
interstitialAd = null
}
override fun onAdClicked() {
// User clicked the ad
}
override fun onAdImpression() {
// Ad impression recorded
}
}
interstitialAd = ad
}
override fun onAdFailedToLoad(error: LoadAdError) {
interstitialAd = null
}
}
)
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
// declared as a field so it can be reassigned from the anonymous callbacks below
private InterstitialAd interstitialAd;
// 2. Create the AdRequest
AdRequest adRequest = new AdRequest.Builder().build();
// 3. Load the interstitial ad
InterstitialAd.load(
context,
"YOUR_AD_UNIT_ID", // Ad unit id configured on Google mediation platform
adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(InterstitialAd ad) {
// 4. Listen to fullscreen lifecycle events
ad.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdShowedFullScreenContent() {
// Ad is now visible fullscreen
}
@Override
public void onAdDismissedFullScreenContent() {
// Ad was closed by the user
interstitialAd = null;
}
@Override
public void onAdFailedToShowFullScreenContent(AdError error) {
// Ad failed to display
interstitialAd = null;
}
@Override
public void onAdClicked() {
// User clicked the ad
}
@Override
public void onAdImpression() {
// Ad impression recorded
}
});
interstitialAd = ad;
}
@Override
public void onAdFailedToLoad(LoadAdError error) {
interstitialAd = null;
}
}
);
Showing the Ad
Once loaded, present the interstitial ad by calling show() with the current Activity:
- Kotlin
- Java
// 5. Present the ad at a natural transition point in your app
interstitialAd?.show(activity)
// 5. Present the ad at a natural transition point in your app
if (interstitialAd != null) {
interstitialAd.show(activity);
}
Mediation settings
Find the full settings list in the Integration Guide and Settings Configuration
Check list
- Ensure Brand Safety is enabled
- Ensure you comply with privacy legal requirements (GDPR/CCPA/GPP)
- Comply with app-ads.txt
- Test with different JSON parameter configurations
- Enable validation mode to ensure key features are working
- Implement proper error handling
- Test on different devices and screen sizes
This page covers AdMob / GAM mediation. If you integrate Teads directly (no mediator), see the direct integration guide.
Prerequisites
- Import the Teads inApp SDK in your project.
- GoogleMobileAds SDK: 23.6.0+
Defining a Custom Event
In order to display a Teads anchored Banner using AdMob or GAM mediation, you need to create a custom event.
AdMob
Follow the custom event documentation on the AdMob dashboard using the below values.
| Name | Value |
|---|---|
| Class Name | tv.teads.adapter.admob.TeadsAdapter |
| Parameter | JSON string (see below) |
GAM
Follow the custom event documentation on GAM using the below values.
| Name | Value |
|---|---|
| Class Name | tv.teads.adapter.admob.TeadsAdapter |
| Parameter | JSON string (see below) |
Custom Event Parameter
The parameter must be a JSON string. The adapter routes to the anchored Banner path as soon as the JSON contains the three required keys (articleUrl, widgetId, installationKey).
| Parameter | Type | Required | Description |
|---|---|---|---|
| articleUrl | String | Yes | The URL of the article/page |
| widgetId | String | Yes | Teads widget ID |
| installationKey | String | Yes | Teads installation key |
| widgetIndex | Int | No | Default 0 |
| userId | String | No | Publisher-provided user identifier |
| extId | String | No | External tracking id |
| extSecondaryId | String | No | Secondary external tracking id |
| obPubImp | String | No | Publisher impression id override |
| pbf | Int | No | Floor price in US dollars. Forwarded to the auction as the placement floor price. |
For testing purposes, use the following:
{"articleUrl":"https://mobile-demo.outbrain.com/","widgetId":"MB_10","installationKey":"NANOWDGT01"}
For production, your articleUrl, widgetId, and installationKey will be unique values provided by your product manager. Contact your local account manager to obtain your production parameters.
Integration
Initialize Google Mobile Ads
Initialize the Google Mobile Ads SDK before loading any ads:
- Kotlin
- Java
import com.google.android.gms.ads.MobileAds
// 1. Initialize AdMob
MobileAds.initialize(context)
import com.google.android.gms.ads.MobileAds;
// 1. Initialize AdMob
MobileAds.initialize(context);
Load and Display the Banner
Add an AdView to your layout, configure it with your AdMob ad unit id and ad size, then call loadAd().
<!-- res/layout/activity_main.xml -->
<FrameLayout
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Build the AdView with an Activity context (not the application context). Google recommends passing an Activity when initializing ad objects so mediated networks behave consistently, and the Teads banner adapter requires it to size the creative — with an application context the Teads ad fails to load.
- Kotlin
- Java
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.AdView
// 2. Build the AdView with a fixed banner size — context MUST be an Activity
val adView = AdView(context).apply {
adUnitId = "YOUR_AD_UNIT_ID" // Ad unit id configured on your Google mediation platform
setAdSize(AdSize.BANNER) // Fixed 320x50dp
}
// 3. Add it to your container and load the ad
findViewById<FrameLayout>(R.id.banner_container).addView(adView)
adView.loadAd(AdRequest.Builder().build())
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
// 2. Build the AdView with a fixed banner size — context MUST be an Activity
AdView adView = new AdView(context);
adView.setAdUnitId("YOUR_AD_UNIT_ID"); // Ad unit id configured on your Google mediation platform
adView.setAdSize(AdSize.BANNER); // Fixed 320x50dp
// 3. Add it to your container and load the ad
((FrameLayout) findViewById(R.id.banner_container)).addView(adView);
adView.loadAd(new AdRequest.Builder().build());
AdSize.BANNER requests a fixed 320x50dp slot from the AdMob waterfall. Use the fixed size, not an adaptive one: adaptive sizes such as AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(...) re-resolve when the view's bounds change (rotation, layout passes), which can trigger duplicate ad requests; the fixed size is invariant. The Teads creative still resizes its own height inside the slot via the JS engine.
Mediation settings
Find the full custom-event JSON parameter list in Settings Configuration — Banner (AdMob Mediation).
Check list
- Ensure Brand Safety is enabled
- Ensure you comply with privacy legal requirements (GDPR/CCPA/GPP)
- Comply with app-ads.txt
- Test with different JSON parameter configurations
- Enable validation mode to ensure key features are working
- Implement proper error handling
- Test on different devices and screen sizes