Skip to main content

Interstitial Ads

Ad Request

Placement

Create a InterstitialRequest.Builder instance, set AdContentType, placement id and other parameters, if applicable.

val interstitialRequestBuilder = InterstitialRequest.Builder()
.setPlacementId(...) // Set placement id
.setAdContentType(...) // Set AdContentType
.setTargetingParams(...) // Set TargatingParams instance
.setPriceFloorParams(...) // Set price floor parameters
.setLoadingTimeOut(...) // Set loading timeout in milliseconds

AdContentType

TypeDescription
AdContentType.AllFlag to request both Video and Static ad content types.
AdContentType.StaticFlag to request Static ad content type only.
AdContentType.VideoFlag to request Video ad content type only.
info

By default AdContentType is AdContentType.All

General Request

Set the InterstitialRequest.AdRequestListener instance to the InterstitialRequest.Builder instance.

interstitialRequestBuilder.setListener(object : InterstitialRequest.AdRequestListener {

override fun onRequestSuccess(request: InterstitialRequest,
auctionResult: AuctionResult) {
// Called when InterstitialRequest was requested successfully
}

override fun onRequestFailed(request: InterstitialRequest,
error: BMError) {
// Called when InterstitialRequest request failed
}

override fun onRequestExpired(request: InterstitialRequest) {
// Called when InterstitialRequest expired
}
})
note

AdRequestListener callbacks run on a background thread, not on the main thread.

When all the necessary parameters are set, call build on the InterstitialRequest.Builder instance:

val interstitialRequest = interstitialRequestBuilder.build()
Keep ad request

You need to keep reference to InterstitialRequest before calling InterstitialRequest.request, otherwise, it is possible it will be cleared by Garbage Collector and callbacks won’t be triggered.

Client Bidding Request

Bid Token

With S2S integration, you will need a BidToken that you need to transfer in the request.

Define AdPlacementConfig:

val adPlacementConfig = AdPlacementConfig.Builder(AdsFormat)
.withPlacementId(...) // Set placement id
.build()

To get a BidToken, you can use one of 2 methods:

// Must be run on background thread
val bidToken = BidMachine.getBidToken(Context, AdPlacementConfig)

or

BidMachine.getBidToken(Context, AdPlacementConfig) { bidToken ->
// The BidToken will be returned on a background thread
}

Bid Payload

After completing the server-side auction, you will receive a Base64-encoded payload string, which must be passed as a parameter to the InterstitialRequest.Builder:

interstitialRequestBuilder.setBidPayload(String?)

When all the necessary parameters are set, call build on the InterstitialRequest.Builder instance:

val interstitialRequest = interstitialRequestBuilder.build()
Keep ad request

You need to keep reference to InterstitialRequest before calling InterstitialRequest.request, otherwise, it is possible it will be cleared by Garbage Collector and callbacks won’t be triggered.

Ad Display

Prepare the Ad Request object

When you need to request an ad and get an AuctionResult, call request on the InterstitialRequest instance.

interstitialRequest.request(...)
info

When you made an in-house meditation and you decided that an advertisement from BidMachine will be shown - call interstitialRequest.notifyMediationWin, if BidMachine lost in mediation - call interstitialRequest.notifyMediationLoss

Destroy the InterstitialRequest instance if you don't need it anymore.

interstitialRequest.destroy()
caution

Don't destroy the InterstitialRequest instance, if it will be used for load the InterstitialAd instance or if the InterstitialAd instance loaded with the InterstitialRequest instance has not been shown yet. Otherwise, ad will not work correctly, which can affect a lower display rate, fill rate, rendering errors, and as a result - lower revenue.

Define Ad Listener

Before execute load on the InterstitialAd instance set the InterstitialListener instance:

val interstitialAd = InterstitialAd(...)
interstitialAd.setListener(object : InterstitialListener {

override fun onAdLoaded(ad: InterstitialAd) {
// Called when Ad was loaded and ready to be displayed
}

override fun onAdLoadFailed(ad: InterstitialAd,
error: BMError) {
// Called when Ad failed to load
}

override fun onAdImpression(ad: InterstitialAd) {
// Called when Ad Impression has been tracked
}

override fun onAdShowFailed(ad: InterstitialAd,
error: BMError) {
// Called when Ad show failed
}

override fun onAdClicked(ad: InterstitialAd) {
// Called when Ad has been clicked
}

override fun onAdClosed(ad: InterstitialAd,
finished: Boolean) {
// Called when Ad was closed (e.g - user clicked the close button)
// finished indicates if the ad was finished (e.g - video playing completed)
}

override fun onAdExpired(ad: InterstitialAd) {
// Called when Ad expired
}

})
interstitialAd.load(interstitialRequest)

Loading and presenting interstitial ads

Make sure that the InterstitialRequest instance have AuctionResult. It's mean ads requested successfully.

interstitialRequest.auctionResult != null

Use onAdLoaded callback to determine the possibility of displaying.

Before displaying, check if the InterstitialAd instance can be displayed:

interstitialAd.canShow()

To display the InterstitialAd instance, you just need to execute show.

interstitialAd.show()

After ad was successful shown and no longer needed, it can be destroyed.

interstitialAd.destroy()
info

You can find code examples written in Java and Kotlin: Github Interstitial