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.
- Kotlin DSL
- Groovy
dependencies {
implementation("com.naver.gfpsdk:extension-aps")
}
dependencies {
implementation 'com.naver.gfpsdk:extension-aps'
}
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.
- Kotlin
- Java
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)
}
}
public class SampleApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AdRegistration.getInstance("APS_KEY", this);
AdRegistration.enableTesting(true); // set false before release
// MRAID configuration
AdRegistration.setMRAIDSupportedVersions(new String[] {"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>
- Kotlin
- Java
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()
}
}
}
public class BannerSampleActivity extends AppCompatActivity {
private RelativeLayout bannerAdContainer;
private GfpBannerAdView bannerAdView; // GFP SDK banner ad view
private AdParam adParam; // GFP SDK Ad Param
private DTBAdRequest dtbAdRequest;
private boolean apsCompleted = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_banner_sample);
bannerAdContainer = findViewById(R.id.banner_container);
initialize();
requestAPS();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (bannerAdView != null) {
bannerAdView.destroy();
}
}
private void initialize() {
adParam = new AdParam.Builder()
.setAdUnitId("GFP_AD_UNIT_ID")
.build();
bannerAdView = new GfpBannerAdView(this, adParam);
bannerAdContainer.addView(bannerAdView);
}
private void requestAPS() {
adParam.setApsParam(null); // reset ApsParam before request.
dtbAdRequest = new DTBAdRequest();
dtbAdRequest.setSizes(new DTBAdSize(320, 100, "YOUR_UUID"));
dtbAdRequest.loadAd(new DTBAdCallback() {
@Override
public void onFailure(@NonNull AdError adError) {
apsCompleted = true;
internalLoadAd();
}
@Override
public void onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
apsCompleted = true;
List<DTBAdSize> adSizes = dtbAdResponse.getDTBAds();
if (adSizes != null && !adSizes.isEmpty()) {
GfpApsAdParam apsAdParam =
ApsUtils.createGfpApsAdParam(dtbAdResponse);
adParam.setApsParam(apsAdParam);
}
internalLoadAd();
}
});
}
private void internalLoadAd() {
if (apsCompleted) {
bannerAdView.loadAd();
}
}
}
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.
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.