Banner Placement
Banner Placement (Direct)
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.
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" />
- Kotlin
- Java
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.
}
}
import android.net.Uri;
import android.os.Bundle;
import android.widget.FrameLayout;
import androidx.appcompat.app.AppCompatActivity;
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;
import java.util.Map;
public class BannerActivity extends AppCompatActivity implements TeadsAdPlacementEventsDelegate {
private TeadsAdPlacementBanner banner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 1. Build the placement configuration — this 4-arg constructor is a real
// Java-visible overload generated for the config's trailing default parameters
TeadsAdPlacementBannerConfig config = new TeadsAdPlacementBannerConfig(
Uri.parse("https://yoursite.com/article"),
"MB_10", // Provided by your Teads account manager
"YOUR_INSTALLATION_KEY",
0
);
// 2. Create the placement and load the ad — context (this) MUST be an Activity
TeadsAdPlacementBanner placement = new TeadsAdPlacementBanner(this, config, this);
banner = placement;
// 3. Attach the returned view to your container
FrameLayout adView = placement.loadAd();
((FrameLayout) findViewById(R.id.banner_container)).addView(adView);
}
@Override
public void onPlacementEvent(TeadsAdPlacement<?, ?> placement, TeadsAdPlacementEventName event, Map<String, ?> data) {
// React to placement lifecycle events — see the Lifecycle Events table below.
}
}
For production, articleUrl, widgetId, and installationKey will be unique values provided by your product manager. Contact your local account manager to obtain them.
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:
| Event | Meaning |
|---|---|
LOADED | Ad data was returned by the server |
READY | Ad is ready to be displayed |
RENDERED | Ad has been rendered on screen |
HEIGHT_UPDATED | Engine reports a new height — read it from data["height"] if you animate the slot |
VIEWED | Ad met viewability criteria |
CLICKED | User tapped the ad (Teads opens the landing URL in a Custom Tab automatically) |
CLICKED_ORGANIC | User tapped an organic recommendation; landing URL is in data["url"] |
FAILED | No ad to display — fall back to other content |
If you use AdMob or GAM mediation instead, see the Mediation — Banner guide.