Skip to main content

Standard Prebid Integration - TeadsPBMPluginRenderer

This article shows you how to deliver Teads ads on your application using the Prebid Mobile SDK. This integration uses the official Prebid Mobile SDK. Teads provides a Plugin Renderer that handles ad display for Teads demand while other demand partners continue working normally.

Experimental

Experimental API.


Sample App

The official Teads SDK sample application includes working Prebid integrations. Use it for implementation examples and as a reference while you set up this integration.

Teads iOS Sample App on GitHub

Prerequisites​

Installation​

Before installing the Teads Prebid plugin, you will need to integrate PrebidMobile SDK into your application.

Installing the Teads Prebid plugin automatically imports the Teads inApp SDK framework.

CocoaPods​

If your project is managing dependencies through CocoaPods, you just need to add this pod in your Podfile.

It will install the Teads adapter along with the Teads inApp SDK.

  1. Add Pod named TeadsPBMPluginRenderer in your Podfile:
pod 'TeadsPBMPluginRenderer', '~> 6.2'
  1. Run the following to install the adapter in your project.
$ pod install --repo-update

Swift Package Manager​

SPM is a tool for managing the distribution of Swift code. It's integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Installing from Xcode​

  1. Add a package by selecting File → Add Packages… in Xcode's menu bar.
  2. Search for the Teads iOS SDK using the repo's URL:
https://github.com/teads/TeadsSDK-iOS
  1. Next, set the Dependency Rule to be Up to Next Major Version and specify 6.2.1 < 7.0.0.
  2. Choose the Teads product that you want to be installed in your app: TeadsPBMPluginRenderer

Alternatively, add Teads to your Package.swift manifest​

  1. Add it to the dependencies of your Package.swift:
dependencies: [
.package(url: "https://github.com/teads/TeadsSDK-iOS", .upToNextMajor(from: "6.2.1"))
]
  1. in any target that depends on a Teads product, add it to the dependencies array of that target:
.target(
name: "MyTargetName",
dependencies: [
.product(name: "TeadsPBMPluginRenderer", package: "Teads"),
]
),

Register the Teads plugin renderer​

You need to register the Teads plugin renderer. Such registration can be done just once during the initialization of your app in AppDelegate or in UIViewController.

import TeadsPBMPluginRenderer
import PrebidMobile

Prebid.registerPluginRenderer(TeadsPBMPluginRenderer())

You can also pass in the plugin renderer constructor a TeadsAdapterSettings class.

import TeadsPBMPluginRenderer
import PrebidMobile

let teadsSettings = TeadsAdapterSettings { (settings) in
settings.enableDebug()
}


Prebid.registerPluginRenderer(TeadsPBMPluginRenderer(settings: teadsSettings))

Specify contextUrl targeting​

Set the publisher's http page URL that matches the content where Teads Ad will be loaded. This value helps to target the context and also guarantees brand safety to our advertisers.

Targeting.shared.addAppExtData(key: "contextUrl", value: "https://example.com/my_article_1")

Settings​

Find the full settings list in Settings Configuration — TeadsAdapterSettings.

Ad Formats​

Currently the Teads plugin renderer supports Media (formerly inRead) only. In the Prebid Mobile SDK that creative is rendered through a Prebid BannerView — this is not the Teads Anchored Banner format.

Image and video

Media can serve image and video, according to your Prebid banner ad unit setup.

If you make use of other ad formats in your Prebid SDK implementation, other demand partners will continue to be able to serve your bid requests normally.

Ad Request​

No additional step should be made on your app implementation in order to request ads, just integrate your Prebid BannerView normally according to the Prebid SDK docs.

Ad Listener​

To be fully aware of the Teads ad lifecycle, subscribe on your Prebid BannerView to the TeadsPBMEventDelegate protocol.

import PrebidMobile
import TeadsPBMPluginRenderer

bannerView?.setPluginEventDelegate(self)
// TeadsPBMEventDelegate conformance
extension MyViewController: TeadsPBMEventDelegate {
func didUpdateRatio(adRatio: TeadsAdRatio) { }
func onAdExpandedToFullScreen() { }
func onAdCollapsedFromFullScreen() { }
func onFailedToLoadAd(reason: String) { }
}
Swift-only

TeadsPBMEventDelegate has no Objective-C equivalent — it is declared without @objc (even though its parent protocol is @objc), so no Objective-C class can conform to it. This feature is Swift-only.

Other ad events such as onAdClicked, onAdDisplayed, and so on can be listened by implementing Prebid BannerViewDelegate protocol directly. Please check all events on the Prebid SDK docs.

Ad Resizing​

This part is a must and not implementing it will drastically affect the fill rate from Teads demand.

Dynamic height

Teads ads can adopt flexible dimensions. Your app must dynamically resize the ad container when the creative requests a new ratio. TeadsAdRatio.calculateHeight(for:) computes the correct height.

It is mandatory to programmatically adapt the size of the ad container via the ratio update delegate method.

import TeadsPBMPluginRenderer
import PrebidMobile

class MyViewController : UIViewController, TeadsPBMEventDelegate {

@IBOutlet weak var slotHeightConstraint: NSLayoutConstraint! // set to 0 in InterfaceBuilder
var bannerView: BannerView?

override func viewDidLoad() {
super.viewDidLoad()

let prebidConfigId = "your-prebid-config-id" // As configured on your Prebid Server
let adEventHandler = BannerEventHandlerStandalone()
adEventHandler.adSizes = [CGSize(width: 300, height: 250)]

bannerView = BannerView(configID: prebidConfigId, eventHandler: adEventHandler)
bannerView?.setPluginEventDelegate(self)
}

func didUpdateRatio(adRatio: TeadsAdRatio) {
guard let bannerView else {
return
}
slotHeightConstraint.constant = adRatio.calculateHeight(for: bannerView.frame.width)
}
}
Swift-only

This sample conforms to TeadsPBMEventDelegate, which has no Objective-C equivalent (see note above) — it is declared without @objc, so no Objective-C class can conform to it. This feature is Swift-only.

PluginRenderer under the hood​

If you look for more understanding regarding how a plugin renderer works over the Prebid Mobile SDK, please find more here.

Prebid Server setup​

Notice that in order to turn your Teads plugin renderer fully functional and leverage from Teads demand you need to wire the Teads Adapter to your Prebid Server, please find more here.

The following configuration for each of your ad slots name is required:

{
"name": "imp-300x250-banner"
}

A placement id provided by your publisher manager is required as the sample below:

{
"ext": {
"teads": {
"placementId": 204344
}
}
}

Checklist​