Skip to content

Interstitial Ads

Interstitial ads are full-screen advertisements that appear at natural transition points in an app, such as between levels or screens.

Example

To create an interstitial ad, start by initializing a BoldwinInterstitial with the following parameters:

  • endpointId - The endpoint ID that identifies the ad placement
  • adSizes - A list of BoldwinAdSize objects that specify the ad sizes
  • adListener - A BoldwinInterstitialListener object that receives callbacks when the ad is loaded, shown, or closed
    private var interstitial: BoldwinInterstitial? = null

private fun createAd() {
    // 1. Create BoldwinInterstitial
    interstitial = BoldwinInterstitial(ENDPOINT_ID, this)

    // 2. Configure listener
    interstitial?.setAdSizes(BoldwinAdSize(320, 480))
    interstitial?.setAdListener(createListener())

    // 3. Load ad
    interstitial?.loadAd()
}

private fun createListener(): BoldwinInterstitialListener = object : BoldwinInterstitialListener {
    override fun onAdLoaded(ad: BoldwinAd?) {
        Log.d(TAG, "Ad loaded: $ad")
        // 4. Show ad
        interstitial?.show()
    }

    override fun onAdFailed(error: BoldwinError?) {
        Log.e(TAG, "Ad failed to load: ${error?.message}")
    }

    override fun onAdOpened() {
        Log.d(TAG, "Ad opened")
    }

    override fun onAdClicked() {
        Log.d(TAG, "Ad clicked")
    }

    override fun onAdClosed() {
        Log.d(TAG, "Ad closed")
    }
}

The constructor of BoldwinInterstitial accepts the endpoint ID that identifies the ad placement.

The loadAd() method loads the ad from the server. When the ad is loaded (after the onAdLoaded() callback), you can show it at any time by calling show(). You can also call it immediately after the onAdLoaded() callback.

Configuration

A single ad unit can be configured to support multiple ad sizes:

    interstitial.setAdSizes(BoldwinAdSize(320, 480), BoldwinAdSize(300, 250))

If ad sizes are not specified, the SDK automatically determines the optimal ad sizes for the device.

Bid Floor

You can set a minimum bid for the ad unit by calling setBidFloor(). The value is expressed in CPM (USD) and is sent in the bid request:

    interstitial.setBidFloor(0.5)

Note: Call this method before loadAd(). If it is not set, or the value is negative, the SDK uses the default bid floor of 0.1. Pass null to reset to the default.