Skip to main content

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.

val nativeAdOptions = GfpNativeAdOptions.Builder()
.setTheme(ResolvedTheme.DARK)
.build()
val adLoader = 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().

The following example demonstrates how to set the AdChoices icon placement to the bottom-right corner for DFP native ads.

val nativeAdOptions = GfpNativeAdOptions.Builder()
.setAdChoicesPlacement(GfpNativeAdOptions.ADCHOICES_BOTTOM_RIGHT)
.build()
val adLoader = 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().

caution

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.

val nativeAdOptions = GfpNativeAdOptions.Builder()
.setHasMediaView(false)
.build()
val adLoader = 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.

info

If no timeout value is set in SdkProperties or GfpAdLoader, the default timeout value of 60 seconds will be applied.

val adLoader = GfpAdLoader.Builder(this, adParam)
.withTimeoutMillis(10_000L)
.withNativeAd { nativeAd ->
// Show the native ad.
}
.build()