The NativeAdUnit is a subclass of the AdUnit class. Use the NativeAdUnit object to create and configure a native ad unit in your app.
Create a new NativeAdUnit
associated with a Prebid Server configuration ID.
See AdUnit for additional parameters and methods.
Parameters
configId (String)
: Prebid Server configuration ID. Note: this is a Prebid Server impression-level stored request ID.
Create a NativeAdUnit
NativeAdUnit nativeAdUnit = new NativeAdUnit("your-config-id");
Configure the NativeAdUnit
// General configuration
nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
// Add event trackers requirements, this is required
ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.JS);
try {
NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods);
nativeAdUnit.addEventTracker(tracker);
} catch (Exception e) {
e.printStackTrace();
}
// Require a title asset
NativeTitleAsset title = new NativeTitleAsset();
title.setLength(90);
title.setRequired(true);
nativeAdUnit.addAsset(title);
// Require an icon asset
NativeImageAsset icon = new NativeImageAsset();
icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON);
icon.setWMin(20);
icon.setHMin(20);
icon.setRequired(true);
nativeAdUnit.addAsset(icon);
// Require an main image asset
NativeImageAsset image = new NativeImageAsset();
image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN);
image.setHMin(200);
image.setWMin(200);
image.setRequired(true);
nativeAdUnit.addAsset(image);
// Require sponsored text
NativeDataAsset data = new NativeDataAsset();
data.setLen(90);
data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED);
data.setRequired(true);
nativeAdUnit.addAsset(data);
// Require main description
NativeDataAsset body = new NativeDataAsset();
body.setRequired(true);
body.setDataType(NativeDataAsset.DATA_TYPE.DESC);
nativeAdUnit.addAsset(body);
// Require call to action
NativeDataAsset cta = new NativeDataAsset();
cta.setRequired(true);
cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT);
nativeAdUnit.addAsset(cta);
Load the NativeAdUnit
nativeAdUnit.fetchDemand(adView, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
// call load ad on the adView
}
});