Native Ad Options
Native ads offer various advanced features that allow for additional customization and provide the best advertising experience. This guide explains how to use the advanced features of native ads.
Configure GfpTheme
Some ads provided through the NDA module are rendered in either a light or dark theme based on the configured GfpTheme value.
You can configure a global GfpTheme using NdaProviderOptions.Builder().setTheme(GfpTheme). However, if you want to apply a GfpTheme to a single ad only, call GfpNativeAdOptions.Builder().setTheme().
- If not set, rendering will follow the DayNight value configured on the device.
- If this option is set, rendering will follow the specified GfpTheme value.
The following example demonstrates how to configure the dark theme.
- Kotlin
- Java
val nativeAdOptions = GfpNativeAdOptions.Builder()
.setTheme(ResolvedTheme.DARK)
.build()
val adLoader = GfpAdLoader.Builder(this, adParam)
...
.withNativeAd(nativeAdOptions) { nativeAd ->
...
}
.build()
GfpNativeAdOptions nativeAdOptions = new GfpNativeAdOptions.Builder()
.setTheme(ResolvedTheme.DARK)
.build();
GfpAdLoader adLoader = new GfpAdLoader.Builder(this, adParam)
...
.withNativeAd(nativeAdOptions, nativeAd -> {
...
})
.build();
AdChoices Placement for DFP Ads
Native ads provided through the DFP module are automatically rendered by the DFP SDK, rather than being rendered within the GfpAdChoicesView added during the layout configuration of GfpNativeAdView.
If you want to change the placement of the AdChoices icon for DFP native ads, you can select the corner where the AdChoices icon will be rendered using GfpNativeAdOptions.Builder.setAdChoicesPlacement().
- If not set, the AdChoices icon will be placed in the top-right corner by default.
- When this option is set, the AdChoices icon will be placed in the specified custom location. The possible values are as follows:
The following example demonstrates how to set the AdChoices icon placement to the bottom-right corner for DFP native ads.
- Kotlin
- Java
val nativeAdOptions = GfpNativeAdOptions.Builder()
.setAdChoicesPlacement(GfpNativeAdOptions.ADCHOICES_BOTTOM_RIGHT)
.build()
val adLoader = GfpAdLoader.Builder(this, adParam)
...
.withNativeAd(nativeAdOptions) { nativeAd ->
...
}
.build()
GfpNativeAdOptions nativeAdOptions = new GfpNativeAdOptions.Builder()
.setAdChoicesPlacement(GfpNativeAdOptions.ADCHOICES_BOTTOM_RIGHT)
.build();
GfpAdLoader adLoader = new GfpAdLoader.Builder(this, adParam)
...
.withNativeAd(nativeAdOptions, nativeAd -> {
...
})
.build();
Configure the Use of GfpMediaView
When configuring a native ad layout without using GfpMediaView, you can set whether to use GfpMediaView through GfpNativeAdOptions.Builder.setHasMediaView().
- If not set or set to
true
, you must include GfpMediaView in the native ad layout and register it with GfpNativeAdView. - If set to
false
, it is possible to configure a layout without GfpMediaView, and there is no need to register GfpMediaView with GfpNativeAdView.
If GfpMediaView is included in the native ad layout and registered with GfpNativeAdView, but GfpNativeAdOptions.Builder.setHasMediaView() is set to false
, an exception will occur.
The following example demonstrates how to configure a layout without GfpMediaView and set it to not use GfpMediaView.
- Kotlin
- Java
val nativeAdOptions = GfpNativeAdOptions.Builder()
.setHasMediaView(false)
.build()
val adLoader = GfpAdLoader.Builder(this, adParam)
...
.withNativeAd(nativeAdOptions) { nativeAd ->
...
}
.build()
GfpNativeAdOptions nativeAdOptions = new GfpNativeAdOptions.Builder()
.setHasMediaView(false)
.build();
GfpAdLoader adLoader = new GfpAdLoader.Builder(this, adParam)
...
.withNativeAd(nativeAdOptions, nativeAd -> {
...
})
.build();
Timeout Configuration
The request timeout value for native ads can be globally configured using SdkPropertiesBuilder.unifiedAdRequestTimeout. However, if you want to set a timeout for a single ad request, you can configure it during the process of building a GfpAdLoader by using the withTimeoutMillis method, as shown in the example below.
The following example demonstrates how to set a timeout value of 10 seconds for a single ad request loaded with a specific GfpAdLoader. When the timeout value for a single ad request is set as shown below, the globally configured timeout value will be ignored.
If no timeout value is set in SdkProperties or GfpAdLoader, the default timeout value of 60 seconds will be applied.
- Kotlin
- Java
val adLoader = GfpAdLoader.Builder(this, adParam)
.withTimeoutMillis(10_000L)
.withNativeAd { nativeAd ->
// Show the native ad.
}
.build()
GfpAdLoader adLoader = new GfpAdLoader.Builder(this, adParam)
.withTimeoutMillis(10_000L)
.withNativeAd(new GfpNativeAd.OnNativeAdLoadedListener() {
@Override
public void onNativeAdLoaded(GfpNativeAd nativeAd) {
// Show the native ad.
}
})
.build();