Combined Ads
GfpAdLoader can be used to combine banner ads, native ads, and native simple ads in a single ad request.
Before Getting Started
- An Ad Unit ID is required to make ad requests.
- Please complete the processes such as setting up the ad provider, configuring inventory, and registering ad units through NAM Admin.
- For related details, please contact the NAM administrator.
- If there are other Views overlaying the ad, exposure measurement may not work properly in some cases, which could result in disadvantages in performance metric measurement.
Load Ads
The GfpAdLoader object can handle ad requests for various formats, including banner, native, and native simple ads. By adding the necessary methods for each ad format during the process of building the GfpAdLoader, you can implement this functionality.
The following code demonstrates how to create a GfpAdLoader that can load banner, native, and native simple ads in a single request.
- Kotlin
- Java
// Create a new ad parameter.
val adParam = AdParam.Builder()
.setAdUnitId("YOUR_AD_UNIT_ID")
...
.build()
// Create a new ad loader.
val adLoader = GfpAdLoader.Builder(this, adParam)
.withBannerAd { bannerAd ->
// Show the banner ad.
}
.withNativeAd { nativeAd ->
// Show the native ad.
}
.withNativeSimpleAd {
// Show the native simple ad.
}
.withAdListener(object: AdEventListener() {
...
})
.build()
// Create a new ad parameter.
AdParam adParam = new AdParam.Builder()
.setAdUnitId("YOUR_AD_UNIT_ID")
...
.build();
// Create a new ad loader.
GfpAdLoader adLoader = new GfpAdLoader.Builder(this, adParam)
.withBannerAd(new GfpBannerAd.OnBannerAdViewLoadedListener() {
@Override
public void onBannerAdViewLoaded(GfpBannerAdView adView) {
// Show the banner ad.
}
}
.withNativeAd(new GfpNativeAd.OnNativeAdLoadedListener() {
@Override
public void onNativeAdLoaded(GfpNativeAd nativeAd) {
// Show the native ad.
}
})
.withNativeSimpleAd(new GfpNativeSimpleAd.OnNativeSimpleAdLoadedListener() {
@Override
public void onNativeSimpleAdLoaded(GfpNativeSimpleAd ad) {
// Show the native simple ad.
}
})
.withAdListener(new AdEventListener() {
...
})
.build();
Here are the individual tasks:
1. withBannerAd() Method
It is recommended to load banner ads through the GfpAdLoader object only when requested together with native or native simple ads. If you want to request banner ads only, follow the steps described in Banner Ads.
The withBannerAd() method prepares the GfpAdLoader to receive banner ads. When a banner ad is successfully loaded, the onBannerAdViewLoaded() method of the specified listener object is called.
You can display the banner ad by adding the GfpBannerAdView, which is passed as an argument to the onBannerAdViewLoaded() method, to a ViewGroup where the ad will be displayed. The example below demonstrates replacing the loaded GfpBannerAdView in a ViewGroup named adContainer.
- Kotlin
- Java
val adLoader = GfpAdLoader.Builder(this, adParam)
.withBannerAd { bannerAd ->
// Replace ad container with loaded banner ad view.
adContainer.removeAllViews()
adContainer.addView(bannerAd)
}
...
.build()
GfpAdLoader adLoader = new GfpAdLoader.Builder(this, adParam)
.withBannerAd(new GfpBannerAd.OnBannerAdViewLoadedListener() {
@Override
public void onBannerAdViewLoaded(GfpBannerAdView adView) {
// Replace ad container with new banner ad view.
adContainer.removeAllViews();
adContainer.addView(bannerAd);
}
}
...
.build();
2. withNativeAd() Method
The withNativeAd() method prepares the GfpAdLoader to receive native ads. When a native ad is successfully loaded, the onNativeAdLoaded() method of the specified listener object is called.
The post-loading process for native ads follows the steps described in the Native Ads section.
3. withNativeSimpleAd() Method
The withNativeSimpleAd() method prepares the GfpAdLoader to receive native simple ads. When a native simple ad is successfully loaded, the onNativeSimpleAdLoaded() method of the specified listener object is called.
The post-loading process for native simple ads follows the steps described in the Native Simple Ads section.