Skip to main content

Getting Started

Native simple ads are a type of native ad that allows rendering native-format ad content easily, similar to banner ads, without complex configurations or additional tasks.


Before You Begin

  • Ad Unit ID is required to call ads.
    • Please complete the process of setting up the ad provider, inventory settings, and registering ad units through the 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 negatively impact performance metrics.

[Step 1] Complete NAM SDK Integration

Please refer to Getting Started.

The following assumes that the NAM SDK integration has been completed.


[Step 2] Define GfpNativeSimpleAdView

First, you need to add GfpNativeSimpleAdView, where the native simple ad will be rendered, to the layout XML file.

info

When adding GfpNativeSimpleAdView to the layout, set the width to either WRAP_CONTENT or MATCH_PARENT, and the height to WRAP_CONTENT to accommodate variable sizes.

If the width is set to WRAP_CONTENT, the width of GfpNativeSimpleAdView will automatically adjust to match the width of the ad creative. On the other hand, if the width is set to MATCH_PARENT, the width will be set to MATCH_PARENT regardless of the creative's width.

<com.naver.gfpsdk.GfpNativeSimpleAdView
android:id="@+id/native_simple_ad_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

[Step 3] Build GfpAdLoader

Native simple ads are loaded through the GfpAdLoader class, which can be created using the GfpAdLoader.Builder class that allows various customizations during the creation process. By setting the withNativeSimpleAd() method, which is considered a declaration to load native simple ads, you can load native simple ads.

When building the GfpAdLoader, you must create and pass an AdParam object as a parameter. This object contains essential information for the ad request, such as the Ad Unit ID, as well as runtime information for a single ad request (e.g., targeting information). For more details about AdParam, please refer to Ad Parameters.

// 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)
.withNativeSimpleAd { nativeAd ->
// Show the native simple ad.
}
.withAdListener(object: AdEventListener() {
...
})
.build()

As shown in the example above, you can create a GfpAdLoader capable of receiving native simple ads using the withNativeSimpleAd() method. When a native simple ad is successfully loaded, the onNativeSimpleAdLoaded() method of the GfpNativeSimpleAd.OnNativeSimpleAdLoadedListener() declared as a parameter is called.


[Step 4] Ad Events

You can receive various events related to the ad lifecycle using the withAdListener() method provided by GfpAdLoader.Builder.

If there are specific events you want to receive, you can selectively override and implement the methods provided by AdEventListener.

val adLoader = GfpAdLoader.Builder(this, adParam)
...
.withAdListener(object : AdEventListener() {
override fun onAdClicked() {
// Called when an ad is clicked.
}

override fun onAdImpression() {
// Called when an impression is recorded for an ad.
}

override fun onAdMuted() {
// Called when an ad is muted.
}

override fun onError(error: GfpError?, responseInfo: GfpResponseInfo?) {
// Called when an error happened while the banner ad is
// attempting to load or rendering an ad.
}
})
.build()

[Step 5] Load an ad

Once the GfpAdLoader has been built, you can load ads using the loadAd() method of the GfpAdLoader.

caution

You need to load ads on the UI thread.

caution

To request ads using a pre-declared GfpAdLoader, you must call only loadAd() without calling cancel(). If you call the cancel() method and then call loadAd(), the request will occur with resources already released, which may lead to issues such as not receiving ad events.

class ExampleActivity : AppCompatActivity() {
private lateinit var adLoader: GfpAdLoader

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_example)

// Create a new ad parameter
val adParam = AdParam.Builder()
.setAdUnitId("YOUR_AD_UNIT_ID")
.build()

// Create a new ad loader
adLoader = GfpAdLoader.Builder(this, adParam)
.withNativeSimpleAd { nativeSimpleAd ->
// Show the native simple ad.
}
.withAdListener(object: AdEventListener() {
...
})
.build()

// Load the native simple ad
adLoader.loadAd()
}
}

[Step 6] Display an Ad

When a native simple ad is successfully loaded, you will receive a GfpNativeSimpleAd object. Unlike native ads, native simple ads only require registering the loaded GfpNativeSimpleAd to a GfpNativeSimpleAdView.

Below is an example of registering a loaded GfpNativeSimpleAd to a GfpNativeSimpleAdView.

class ExampleActivity : AppCompatActivity() {
private lateinit var adLoader: GfpAdLoader

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_example)

// Create a new ad parameter
val adParam = AdParam.Builder()
.setAdUnitId("YOUR_AD_UNIT_ID")
.build()

// Create a new ad loader
adLoader = GfpAdLoader.Builder(this, adParam)
.withNativeSimpleAd { nativeSimpleAd ->
// Assumes you have a native simple ad view in your View layout
val nativeSimpleAdView: GfpNativeSimpleAdView = findViewById(R.id.native_simple_ad_view)

// Call the GfpNativeSimpleAdView's setNativeSimpleAd method
// to register the native simple ad object.
nativeSimpleAdView.setNativeSimpleAd(nativeSimpleAd)
}
.withAdListener(object: AdEventListener() {
...
})
.build()

// Load the native simple ad
adLoader.loadAd()
}
}

[Step 7] Release Resources

When the display of a native simple ad is complete, you must call the cancel() method to release the resources allocated to the ad.

caution

To request ads using a pre-declared GfpAdLoader, you must call only loadAd() without calling cancel(). If you call the cancel() method and then call loadAd(), the request will occur with resources already released, which may lead to issues such as not receiving ad events.

info

The cancel() method must be called for all ads, even if they are not used or referenced.

Below is an example of releasing all references to GfpAdLoader used within an Activity in the onDestroy() method of the Activity.

override fun onDestroy() {
adLoader?.destroy()
super.onDestroy()
}