Skip to main content

Interstitial Ads

InterstitialRequest

Setup InterstitialRequest builder

To create a InterstitialRequest instance, you need to create a InterstitialRequest.Builder instance, set all the necessary parameters and call build on it.

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

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

Set AdRequestListener

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

interstitialRequestBuilder.setListener(object : InterstitialRequest.AdRequestListener {

/**
* Called when InterstitialRequest was requested successfully
*
* @param request - InterstitialRequest instance
* @param auctionResult - AuctionResult info
*/
override fun onRequestSuccess(request: InterstitialRequest,
auctionResult: AuctionResult) {

}

/**
* Called when InterstitialRequest request failed
*
* @param request - InterstitialRequest instance
* @param error - BMError with additional info about error
*/
override fun onRequestFailed(request: InterstitialRequest,
error: BMError) {

}

/**
* Called when InterstitialRequest expired
*
* @param request - InterstitialRequest instance
*/
override fun onRequestExpired(request: InterstitialRequest) {

}
})
note

AdRequestListener callbacks are delivered on the background thread, not the main one.

Build InterstitialRequest

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.

Request InterstitialRequest

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 InterstitialRequest

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.

InterstitialAd

Load InterstitialAd

When you would like to load and display requested Ads:

  • Make sure that the InterstitialRequest instance have AuctionResult. It's mean ads requested successfully.
interstitialRequest.auctionResult != null
  • Make sure that theInterstitialRequest instance not expired.
!interstitialRequest.isExpired

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

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

/**
* Called when Ad was loaded and ready to be displayed
*
* @param ad - InterstitialAd instance
*/
override fun onAdLoaded(ad: InterstitialAd) {

}

/**
* Called when Ad failed to load
*
* @param ad - InterstitialAd instance
* @param error - BMError with additional info about error
*/
override fun onAdLoadFailed(ad: InterstitialAd,
error: BMError) {

}

/**
* Called when Ad Impression has been tracked
*
* @param ad - InterstitialAd instance
*/
override fun onAdImpression(ad: InterstitialAd) {

}

/**
* Called when Ad show failed
*
* @param ad - InterstitialAd instance
* @param error - BMError with additional info about error
*/
override fun onAdShowFailed(ad: InterstitialAd,
error: BMError) {

}

/**
* Called when Ad has been clicked
*
* @param ad - InterstitialAd instance
*/
override fun onAdClicked(ad: InterstitialAd) {

}

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

}

/**
* Called when Ad expired
*
* @param ad - InterstitialAd instance
*/
override fun onAdExpired(ad: InterstitialAd) {

}

})
interstitialAd.load(interstitialRequest)

Use onAdLoaded callback to determine the possibility of displaying

Show InterstitialAd

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()

Destroy InterstitialAd

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