Prerequisites
- Import the Teads inApp SDK in your project.
- GoogleMobileAds SDK: 20+
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:22.6.0' // or higher
// Teads inApp SDK
implementation("tv.teads.sdk.android:sdk:5.x.x@aar") {
transitive = true
}
// Teads Admob Adapter
implementation 'tv.teads.sdk.android:admobadapter:5.x.x'
}
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
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()
Load an ad
Create the TeadsMediationSettings, then add the settings to the AdRequest using toBundle() method
val settings = TeadsMediationSettings.Builder()
.enableDebug()
.build()
val adRequest = AdRequest.Builder()
.addNetworkExtrasBundle(TeadsNativeAdapter::class.java, settings.toBundle())
.build()
adLoader.loadAd(adRequest)
Populate the ad
We can then populate and customize our NativeAdView according the data we have received
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)
}
Mediation settings
Find the full settings list here
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