Skip to main content

Banner Placement

Banner placements display an anchored banner ad inline in your layout. In the direct integration the JS engine drives the banner height — set the container height to wrap_content and it resizes as the creative loads. Use the direct integration when you don't use AdMob or GAM mediation.

warning

Use an Activity context to create TeadsAdPlacementBanner (not the application context). The SDK uses it to size the creative correctly. Passing the application context can cause the ad to be mis-sized.

<!-- res/layout/activity_main.xml -->
<FrameLayout
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
import android.os.Bundle
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.net.toUri
import tv.teads.sdk.combinedsdk.TeadsAdPlacementEventName
import tv.teads.sdk.combinedsdk.adplacement.TeadsAdPlacementBanner
import tv.teads.sdk.combinedsdk.adplacement.config.TeadsAdPlacementBannerConfig
import tv.teads.sdk.combinedsdk.adplacement.interfaces.TeadsAdPlacementEventsDelegate
import tv.teads.sdk.combinedsdk.adplacement.interfaces.core.TeadsAdPlacement

class BannerActivity : AppCompatActivity(), TeadsAdPlacementEventsDelegate {

private var banner: TeadsAdPlacementBanner? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// 1. Build the placement configuration
val config = TeadsAdPlacementBannerConfig(
articleUrl = "https://yoursite.com/article".toUri(),
widgetId = "MB_10", // Provided by your Teads account manager
installationKey = "YOUR_INSTALLATION_KEY",
widgetIndex = 0
)

// 2. Create the placement and load the ad — context (this) MUST be an Activity
val placement = TeadsAdPlacementBanner(this, config, this)
banner = placement

// 3. Attach the returned view to your container
val adView = placement.loadAd()
findViewById<FrameLayout>(R.id.banner_container).addView(adView)
}

override fun onPlacementEvent(
placement: TeadsAdPlacement<*, *>,
event: TeadsAdPlacementEventName,
data: Map<String, Any>?
) {
// React to placement lifecycle events — see the Lifecycle Events table below.
}
}
warning

For production, articleUrl, widgetId, and installationKey will be unique values provided by your product manager. Contact your local account manager to obtain them.

info

Keep the host container's height as wrap_content. A fixed height clips the ad because the JS engine resizes the view dynamically as the creative loads.

Lifecycle Events

The Banner placement uses the standard TeadsAdPlacementEventsDelegate. The key events are:

EventMeaning
LOADEDAd data was returned by the server
READYAd is ready to be displayed
RENDEREDAd has been rendered on screen
HEIGHT_UPDATEDEngine reports a new height — read it from data["height"] if you animate the slot
VIEWEDAd met viewability criteria
CLICKEDUser tapped the ad (Teads opens the landing URL in a Custom Tab automatically)
CLICKED_ORGANICUser tapped an organic recommendation; landing URL is in data["url"]
FAILEDNo ad to display — fall back to other content

If you use AdMob or GAM mediation instead, see the Mediation — Banner guide.