Integrate Inline Ads

Inline ads are only available on Android platforms; they are currently not supported on Amazon.

To integrate any ad format, you must first have completed the instructions in the basic integration article.

An inline ad is a full screen or non-full screen ad that seamlessly integrates within the app content. The publisher determines the location of the ad container within their app. Inline ads can display anywhere you specify on the screen, and the user can continue using the app while the ad plays. 

inLine.png inline 2.png inline 3.png

 

VungleAdSize

The Vungle SDK supports both standard and custom ad sizes.

Standard VungleAdSize

The following table lists the standard ad sizes:

VungleAdSize Constant Dimensions in DP (WxH)
BANNER 320 x 50
BANNER_SHORT 300 x 50
MREC 300 x 250
BANNER_LEADERBOARD 728 x 90

Custom Ad Size

To define a custom inline ad size, set your size using getAdSizeWithWidthAndHeight().

KotlinJava
VungleAdSize.getAdSizeWithWidthAndHeight(widthInDip, heightInDip)

Integrate Inline Ads Using the VungleBannerView Instance

Integrate inline ads using the VungleBannerView instance described in this article (the legacy  BannerAd instance you may be familiar with is deprecated). 

The size of the inline ad container can be customized by passing the adView size to the SDK, or you can use standard sizes, as described in the VungleAdSize section above.

Create, Load, and Play an Inline Ad

  1. Create one view container.

  2. Create a VungleBannerView instance and add this view to the container.

  3. Load ads. To create the inline ads, use the VungleBannerView instance and create a custom ad size using VungleAdSize. Add the following code to your method where you want to prepare the VungleBannerView instance. You will need to provide the Placement ID and VungleAdSize. The Placement ID you use should have been set up in the Monetize Dashboard to work with the type of inline ad to be displayed.

    In addition to the standard ad sizes, Vungle lets you serve any sized ad unit into an app. To set a custom size, use the VungleAdSize API getAdSizeWithWidthAndHeight.


    KotlinJava
    import com.vungle.ads.VungleBannerView
    
    val bannerAdContainer = FrameLayout(context)
    
    val vngAdSize = VungleAdSize.getAdSizeWithWidthAndHeight(300, 400)
              
    val bannerAd = VungleBannerView(context, placementId, vngAdSize).apply {
        adListener = this@BannerFragment
        load()
    }.also {
        val layoutParams = FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT,
            Gravity.CENTER
        )
        bannerAdContainer.addView(it, layoutParams)
    }
    

The ad plays automatically once loaded.

Dismiss an Inline Ad

When the inline ad playback is completed, we recommend cleaning up the instance by calling finishAd().

KotlinJava
bannerAd.finishAd()
bannerAd.adListener = null

Register for Callbacks

To receive notifications for ad events, declare conformance to BannerAdListener protocol and implement callback methods.

KotlinJava
val listener = object: BannerAdListener {
	override fun onAdLoaded(baseAd: BaseAd) {
	Log.d(TAG, "Creative id:" + baseAd.creativeId)
	}
	override fun onAdStart(baseAd: BaseAd) {
	}
	override fun onAdImpression(baseAd: BaseAd) {
	}
	override fun onAdEnd(baseAd: BaseAd) {
	}
	override fun onAdClicked(baseAd: BaseAd) {
	}
	override fun onAdLeftApplication(baseAd: BaseAd) {
	}
	override fun onAdFailedToLoad(baseAd: BaseAd, adError: VungleError) {
	}
	override fun onAdFailedToPlay(baseAd: BaseAd, adError: VungleError) {
	}
}

Test an Inline Ad

You can test an inline ad in one of two ways: by setting your app status to Test Mode so that Vungle can deliver test ads to your app, or by adding a test device to your app so that Vungle can deliver test ads specifically to the test device. Follow the instructions in Test Your Integration: Test Mode and Test Devices.

Additional Resources

  • Refer to our inline ad examples in Kotlin or Java.

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!

Was this article helpful?