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.
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()
.
VungleAdSize.getAdSizeWithWidthAndHeight(widthInDip, heightInDip)
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
- Create one view container.
- Create a
VungleBannerView
instance and add this view to the container.
- Load ads. To create the inline ads, use the
VungleBannerView
instance and create a custom ad size usingVungleAdSize
. Add the following code to your method where you want to prepare theVungleBannerView
instance. You will need to provide the Placement ID andVungleAdSize
. 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
APIgetAdSizeWithWidthAndHeight
.
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) }
import com.vungle.ads.VungleBannerView; FrameLayout bannerAdContainer = new FrameLayout(context); VungleAdSize vngAdSize = VungleAdSize.getAdSizeWithWidthAndHeight(300, 400); VungleBannerView bannerAd = new VungleBannerView(context, placementId, vngAdSize); ViewGroup.LayoutParams params = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER); bannerAdContainer.addView(bannerAd, params); bannerAd.setAdListener(this); bannerAd.load(null);
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()
.
bannerAd.finishAd()
bannerAd.adListener = null
bannerAd.finishAd();
bannerAd.setAdListener(null);
Register for Callbacks
To receive notifications for ad events, declare conformance to BannerAdListener
protocol and implement callback methods.
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) {
}
}
BannerAdListener listener = new BannerAdListener {
@override
public void onAdLoaded(@NonNull BaseAd: baseAd) {
Log.d(TAG, "Creative id:" + baseAd.creativeId)
}
@override
public void onAdStart(@NonNull BaseAd: baseAd) {
}
@override
public void onAdImpression(@NonNull BaseAd: baseAd) {
}
@override
public void onAdEnd(@NonNull BaseAd: baseAd) {
}
@override
public void onAdClicked(@NonNull BaseAd: baseAd) {
}
@override
public void onAdLeftApplication(@NonNull BaseAd: baseAd) {
}
@override
public void onAdFailedToLoad(@NonNull BaseAd: baseAd, @NonNull VungleError: vungleError) {
}
@override
public void onAdFailedToPlay(@NonNull BaseAd: baseAd, @NonNull VungleError: 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.