Skip to main content

Native Simple Ad Options

Native simple 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 simple ads.

GfpTheme Configuration

Some ads provided through the NDA module are rendered in either a light theme or a dark theme depending 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, you can call GfpNativeSimpleAdOptions.Builder().setTheme().

  • If not set, the rendering will follow the DayNight value configured on the device.
  • If this option is set, the rendering will follow the specified GfpTheme value.

Below is an example of how to configure the dark theme.

val nativeSimpleAdOptions = GfpNativeSimpleAdOptions.Builder()
.setTheme(ResolvedTheme.DARK)
.build()
val adLoader = GfpAdLoader.Builder(this, adParam)
...
.withNativeSimpleAd(nativeSimpleAdOptions) { nativeSimpleAd ->
...
}
.build()

AdChoices Placement

Unlike native ads, where you could use GfpAdChoicesView to place the AdChoices icon in a custom position, the AdChoices icon for native simple ads is automatically added to a specified corner by the SDK.

To change the AdChoices placement for native simple ads, you can use the GfpNativeSimpleAdOptions.Builder.setAdChoicesPlacement() method to select the corner where the AdChoices icon will be rendered.

Below is an example of how to set the AdChoices icon placement to the bottom-right corner for native simple ads.

val nativeSimpleAdOptions = GfpNativeSimpleAdOptions.Builder()
.setAdChoicesPlacement(GfpNativeSimpleAdOptions.ADCHOICES_BOTTOM_RIGHT)
.build()
val adLoader = GfpAdLoader.Builder(this, adParam)
...
.withNativeSimpleAd(nativeSimpleAdOptions) { nativeSimpleAd ->
...
}
.build()

Background Style Configuration

Some ads provided through the NDA module allow for background customization. To use another style for dark theme, use setBackgroundStyleForDarkMode.

GfpNativeSimpleAdOptions.Builder()
.setBackgroundStyle(
GfpNativeSimpleBackgroundStyle(
Color.rgb(237, 240, 244), // background color
0.74f, // background alpha
8, // corner radius (dp)
8, // left margin (dp)
0, // top margin (dp)
8, // right margin (dp)
0, // bottom margin (dp)
414, // max width (dp)
null, // shadow color
0f, // shadow alpha
0, // shadow horizontal offset(dp)
0, // shadow vertical offset(dp)
0 // shadow blur radius (dp)
)
)
.build()

Timeout Configuration

The request timeout value for native ads can be set globally using SdkPropertiesBuilder.unifiedAdRequestTimeout. However, if you want to set a timeout for a single ad request, you can configure it during the GfpAdLoader build process 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)
.withNativeSimpleAd { nativeSimpleAd ->
// Show the native simple ad.
}
.build()