Skip to main content

Banner Placement

Banner placements display an anchored adaptive ad pinned to a fixed slot in your view hierarchy. The banner auto-resizes as the ad renders — pin it with Auto Layout (centre + bottom shown below) instead of a fixed-height frame so the JS engine can drive its own height. Use the direct integration when you don't use AdMob mediation.

import UIKit
import TeadsSDK

final class BannerViewController: UIViewController, TeadsAdPlacementEventsDelegate {

private var banner: TeadsAdPlacementBanner?

override func viewDidLoad() {
super.viewDidLoad()

// 1. Build the placement configuration
let config = TeadsAdPlacementBannerConfig(
articleUrl: URL(string: "https://yoursite.com/article")!,
widgetId: "MB_10", // Provided by your Teads account manager
installationKey: "YOUR_INSTALLATION_KEY"
)

// 2. Create the placement and load the ad
let placement = TeadsAdPlacementBanner(config, delegate: self)
banner = placement

do {
let adView = try placement.loadAd()

// 3. Pin it to your view hierarchy (do not use a fixed-height frame).
adView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(adView)
NSLayoutConstraint.activate([
adView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
adView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
adView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
} catch {
print("Failed to load banner: \(error)")
}
}

// MARK: - TeadsAdPlacementEventsDelegate

func adPlacement(
_ placement: TeadsAdPlacementIdentifiable?,
didEmitEvent event: TeadsAdPlacementEventName,
data: [String: Any]?
) {
// React to placement lifecycle events — see the Event Handling section 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

The banner drives its own height from the JS engine. Don't constrain it to a fixed height — that will clip the creative as it resizes.

Lifecycle Events

The Banner placement uses the standard TeadsAdPlacementEventsDelegate. The events you'll typically observe on a banner:

EventMeaning
loadedAd data was returned by the server
readyAd is ready to be displayed
renderedAd has been rendered on screen
heightUpdatedEngine reports a new height — read it from data["height"] if you animate the slot
viewedAd met viewability criteria
clickedUser tapped the ad (the SDK opens the landing URL automatically)
clickedOrganicUser tapped an organic recommendation; landing URL is in data["url"]
failedNo ad to display — fall back to other content

See Event Handling below for the full switch template covering all TeadsAdPlacementEventName cases.

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