In this article, the PID 84242 will be used, you can find more PIDs on this article
In the v5 of the SDK, we've introduced a new class called InReadAdPlacement
which is responsible for configuring the ad placement and then make the call to our ad server.
Settings
In v4 integration, all settings needed for an ad request was placed in the AdSettings
class.
In v5, the setup will be done in two different places, the first one is done during the ad placement configuration, the other one for the ad request.
Below, an example of the new placement and request settings.
val placementSettings = AdPlacementSettings.Builder()
.enableDebug()
.build()
val requestSettings = AdRequestSettings.Builder()
.pageSlotUrl("https://teads.com")
.build()
Placement
Unlike the v4 integration we don't have to instantiate the InReadAdView
, it will be served by the placement once an ad is received.
The first step is to create our InReadAdPlacement
with the optional AdPlacementSettings
created.
val placementSettings = AdPlacementSettings.Builder()
.enableDebug()
.build()
val adPlacement = TeadsSDK.createInReadPlacement(constext, 84242, placementSettings) //replace with the right placement id
Request an ad
Now we can request an ad. We just have to call the requestAd
method from our placement with the settings and a listener.
val requestSettings = AdRequestSettings.Builder()
.pageSlotUrl("https://teads.com")
.build()
adPlacement.requestAd(requestSettings, object : InReadAdListener {
override fun onAdReceived(inReadAdView: InReadAdView, adRatio: AdRatio) {
this@InReadScrollViewFragment.inReadAdView = inReadAdView
adSlotView.addView(inReadAdView, 0)
}
override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) {}
override fun onAdClicked() {}
override fun onAdClosed() {}
override fun onAdError(code: Int, description: String) {}
override fun onAdImpression() {}
override fun onFailToReceiveAd(failReason: String) {}
})
Display an ad
When an ad is received, we just have to add the provided InReadAdView
in the view parent.
⚠️ Note that the view needs to be at the top of the view parent to avoid potential overlay.
override fun onAdReceived(inReadAdView: InReadAdView, adRatio: AdRatio) {
this@InReadScrollViewFragment.inReadAdView = inReadAdView
adSlotView.addView(inReadAdView)
}
AdOpportunityTrackerView
The AdOpportunityTrackerView
is a view that you will need to add to your slot view.
You should add it using in adOpportunityTrackerView
callback method.
Its function is to monitor the inventory.
Once the AdOpportunityTrackerView
is visible, it will be automatically removed.
override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) {
adSlotView.addView(trackerView)
}
Validate your integration
In order to validate that your integration is well done you can use our validation tool.
To do that you just have to enable it in the TeadsAdRequestSettings
like that:
val requestSettings = AdRequestSettings.Builder()
.enableValidationMode()
.build()
adPlacement.requestAd(requestSettings, listener)
Compile, then go to the view that contains your ad, and you just have to follow along with the instructions.
IMPORTANT: ⚠️ don't forget to remove this setting before going in production! ⚠️