Header Bidding
Header bidding is a system where programmatic bids are collected from the publisher's app and sent to the NAM server for ad requests. The NAM SDK supports header bidding for banner ads through the APS (Amazon Publisher Services) module.
While using header bidding may result in longer ad load times, it allows for serving higher-priced ads, maximizing revenue.
Add the APS SDK
Add the dependency for the APS mediation module to the app-level build.gradle.
To use header bidding through the APS module, please contact the NAM administrator.
If you explicitly set the version of the APS mediation dependency, note that the APS SDK version compatible with the NAM SDK is version 9.8.8 or higher.
- Kotlin DSL
- Groovy
dependencies {
implementation("com.naver.gfpsdk.mediation:nam-aps:<latest-version>")
}
dependencies {
implementation 'com.naver.gfpsdk.mediation:nam-aps:<latest-version>'
}
Initializing the APS SDK
To use the APS SDK, you need to initialize it in Application.onCreate() as shown below.
- Kotlin
- Java
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
...
AdRegistration.getInstance("YOUR_APS_APP_KEY", this)
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("YOUR_APS_APP_KEY", this);
AdRegistration.setMRAIDSupportedVersions(new String[] {"1.0", "2.0", "3.0"});
AdRegistration.setMRAIDPolicy(MRAIDPolicy.CUSTOM);
}
}
Load a Banner Ads
To integrate APS banner ads into the NAM SDK, you must first load the APS banner ads. Before loading NAM banner ads, if the APS banner ads are successfully loaded, the DTBAdResponse object received should be added to the AdParam and then GfpBannerAdView.loadAd() should be called. If loading fails, GfpBannerAdView.loadAd() should be called without passing the DTBAdResponse object.
- Kotlin
- Java
class ExampleActivity : AppCompatActivity() {
private lateinit var bannerAdView: GfpBannerAdView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_example)
// The view container of banner ad view
val bannerAdContainer = findViewById(R.id.banner_ad_container)
// Create a new ad parameter
val adParam = AdParam.Builder()
.setAdUnitId("YOUR_AD_UNIT_ID")
.build()
// Create a new banner ad view
bannerAdView = GfpBannerAdView(this, adParam)
// Add the banner ad view to the view container
bannerAdContainer.addView(bannerAdView)
...
val dtbAdRequest = DTBAdRequest()
dtbAdRequest.sizes = DTBAdSize(320, 100, "YOUR_UUID")
dtbAdRequest.loadAd(object: DTBAdCallback {
override fun onFailure(adError: AdError) {
bannerAdView.loadAd()
}
override fun onSuccess(dtbAdResponse: DTBAdResponse) {
val adSizes = dtbAdResponse.dtbAds
if (adSizes != null && adSizes.isNotEmpty()) {
val apsAdParam = ApsUtils.createGfpApsAdParam(dtbAdResponse)
adParam.apsParam = apsAdParam
}
bannerAdView.loadAd()
}
})
}
override fun onDestroy() {
bannerAdView.destroy()
super.onDestroy()
}
}
public class ExampleActivity extends AppCompatActivity {
private GfpBannerAdView bannerAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
// The view container of banner ad view
FrameLayout bannerAdContainer = findViewById(R.id.banner_ad_container);
// Create a new ad parameter.
AdParam adParam = new AdParam.Builder()
.setAdUnitId("YOUR_AD_UNIT_ID")
.build();
// Create a new banner ad view.
bannerAdView = new GfpBannerAdView(this, adParam);
...
DtbAdRequest dtbAdRequest = new DTBAdRequest();
dtbAdRequest.setSizes(new DTBAdSize(320, 100, "YOUR_UUID"));
dtbAdRequest.loadAd(new DTBAdCallback() {
@Override
public void onFailure(@NonNull AdError adError) {
bannerAdView.loadAd();
}
@Override
public void onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
List<DTBAdSize> adSizes = dtbAdResponse.getDTBAds();
if (adSizes != null && !adSizes.isEmpty()) {
GfpApsAdParam apsAdParam =
ApsUtils.createGfpApsAdParam(dtbAdResponse);
adParam.setApsParam(apsAdParam);
}
bannerAdView.loadAd();
}
});
}
@Override
protected void onDestroy() {
bannerAdView.destroy();
super.onDestroy();
}
private void initialize() {
adParam = new AdParam.Builder()
.setAdUnitId("GFP_AD_UNIT_ID")
.build();
bannerAdView = new GfpBannerAdView(this, adParam);
bannerAdContainer.addView(bannerAdView);
}
}
When reusing a single AdParam object to request APS ads multiple times, you must call the AdParam.buildUpon().setApsParam(null) method right before the request to create a new AdParam object. This ensures that the GfpApsAdParam value in the previously set AdParam is reset.
After loading APS banner ads using DtbAdRequest.loadAd(), you must pass the GfpApsAdParam object to the AdParam when the onSuccess() callback is delivered. If the onFailure() callback is delivered, you should proceed without passing the GfpApsAdParam object.
Testing the APS SDK
When enabling test mode for the APS SDK, you can receive test ads. The following example demonstrates how to enable test mode.
Test mode must be disabled in the release build.
- Kotlin
- Java
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
...
AdRegistration.enableTesting(true)
AdRegistration.enableLogging( true )
}
}
public class SampleApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
...
AdRegistration.enableTesting(true);
AdRegistration.enableLogging(true);
}
}
APS Guide
For detailed instructions on using APS, please refer to the APS Android Guide. You will need to log in with your Amazon account.