Skip to main content

Header Bidding

NAM SDK supports header binding only for banner advertisements.

Header bidding is the ad (auction) request process directly from the app to an external Ad DSP (APS) without going through the NAM server.

Loading ads may take a longer response time. However, better (more expensive) ads will be received.


Dependency

Set related repositories and dependencies in the app-level build.gradle file.

dependencies {
implementation("com.naver.gfpsdk:extension-aps")
}
caution

To add the APS SDK dependency, version 9.8.8 or higher is compatible with the NAM SDK.


APS initialization and MRAID settings

Perform APS initialization and MRAID settings in Application.

class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()

AdRegistration.getInstance("APS_KEY", this)
AdRegistration.enableTesting(true) // set false before release
// MRAID configuration
AdRegistration.setMRAIDSupportedVersions(arrayOf("1.0", "2.0", "3.0"))
AdRegistration.setMRAIDPolicy(MRAIDPolicy.CUSTOM)
}
}

Example of banner ad integration

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:id="@+id/banner_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
class BannerSampleActivity : AppCompatActivity() {
private lateinit var bannerAdContainer: RelativeLayout
private lateinit var bannerAdView: GfpBannerAdView // GFP SDK banner ad view
private lateinit var adParam: AdParam // GFP SDK Ad Param

private lateinit var dtbAdRequest: DTBAdRequest

private var apsCompleted = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_banner_sample)
bannerAdContainer = findViewById(R.id.banner_container)

initialize()
requestAPS()
}

override fun onDestroy() {
super.onDestroy()
bannerAdView.destroy()
}

private fun initialize() {
adParam = AdParam.Builder()
.setAdUnitId("GFP_AD_UNIT_ID")
.build()
bannerAdView = GfpBannerAdView(this, adParam)
bannerAdContainer.addView(bannerAdView)
}

private fun requestAPS() {
adParam.apsParam = null // reset ApsParam before request.
dtbAdRequest = DTBAdRequest()
dtbAdRequest.sizes = DTBAdSize(320, 100, "YOUR_UUID")
dtbAdRequest.loadAd(object: DTBAdCallback {
override fun onFailure(adError: AdError) {
apsCompleted = true
internalLoadAd()
}

override fun onSuccess(dtbAdResponse: DTBAdResponse) {
apsCompleted = true
val adSizes = dtbAdResponse.dtbAds
if (adSizes != null && adSizes.isNotEmpty()) {
val apsAdParam = ApsUtils.createGfpApsAdParam(dtbAdResponse)
adParam.apsParam = apsAdParam
}
internalLoadAd()
}
})
}

private fun internalLoadAd() {
if (apsCompleted) {
bannerAdView.loadAd()
}
}
}
caution

When requesting multiple APS advertisements with a single AdParam instance when calling APS, make sure to initialize the GfpApsAdParam value in adParam by calling adParam.setApsParam(null) right before the request.

info

When calling APS, make sure to add the APS response value to the AdParam instance value. When the response to dtbAdRequest.loadAd() is onSuccess(), the GfpApsAdParam object must be passed to adParam through adParam.setApsParam(GfpApsAdParam).

At this point, GfpApsAdParam can be created through ApsUtils.createGfpApsAdParam(DTBAdResponse).


APS Guide

For detailed instructions on how to use APS, please refer to the APS Android Guide.

Log-in is required with an Amazon account.