Native ads Integration Guide
The Appnext Native Ads SDK allows developers to fetch fully customizable native ad data and render it seamlessly within their own app UI. This ad unit provides flexibility to design your own ad layouts while maintaining full control over ad rendering.
Step 1. Loading Native Ads
To request native ads, use the NativeAd class. You can specify the placementId, listener for callbacks, and an optional search keyword.
val nativeAd = NativeAd()
nativeAd.loadAds(
context = this,
placementId = "YOUR_PLACEMENT_ID",
listener = object : NativeAdCallback {
override fun onNativeAdsReceivedSuccessful(ads: List<AppnextNativeApp>) {
displayNativeAds(ads)
}
override fun onNativeAdsReceivedError(error: AppnextError) {
Log.e("Appnext", "Failed to load ads: ${error.errorMessage}")
}
},
searchKeyWord = "games" // Optional
)
Step 2. Optional Configuration Methods
The NativeAd class exposes setter methods that let you pre-configure a request before calling loadAds(). All setters are optional unless otherwise stated.
- setPlacementId - String. Set the Appnext placement ID.
- setCategories - String. Set preferred ad categories (comma-separated)
- setSpecificCategories -String. Set specific ad categories (comma-separated)
- setSearchByPackage - String. Set specific package
- setPostBack - String. Postback parameters that will be posted to your server after the user installs an app (make sure to encode the values).
- setMaxResults - Integer. Limit the maximum number of ads returned in a single response.
Step 3. Handling the Ad Data
Each ad is returned as an AppnextNativeApp object containing all relevant data. You can use these fields to build your own UI.
data class AppnextNativeApp(
val androidPackage: String = "",
val campaignGoal: String = "",
val bannerId: String = "",
val ecpm: String = "",
val market_url: String = "",
val campaignId : String ="",
val categories : String = "",
val revenueType : String = "",
val title: String = "",
val desc: String = "",
val urlImg: String = "", // The app icon
val urlImgWide: String = "", // The app banner
val buttonText: String = "",
val urlVideo: String = "", // Campaign video if available
val urlVideoHigh: String = "",
val urlVideo30Sec: String = "",
val urlVideo30SecHigh: String = "",
val storeRating: String = "",
val storeDownloads: String = "",
val developer_info: String = "",
val advertiser_name: String = "",
val advertiser_entity: String = "",
val advertiser_website: String = "",
val inn: String = "",
val token: String = "",
val storeTotalReviews: String = "",
val creatives : List<CreativeItem> = emptyList() //IF AVAILABLE- campaigns will return with a variety of banner resolutions.(320x50, 320x100, 300x250, 320x480, 480x320, 1280x468, 1280x720, 1280x672, 1280x520, 1440x1040, 1080x1920)
)
Step 4. Reporting Impression & Click Events
After rendering and showing an ad, you must report impressions and click events manually.
Single impression:
NativeAd.sendImpression(bannerId = ad.bannerId, placementId = "YOUR_PLACEMENT_ID")
Batch impressions:
NativeAd.sendImpressionList(bannerIds = ads.map { it.bannerId }, placementId = "YOUR_PLACEMENT_ID")
Click + open:
NativeAd.sendClickAndOpen(bannerId = ad.bannerId, placementId = "YOUR_PLACEMENT_ID") //this will report the click and will open the ad in the required place (play store for example)
Step 5. Callbacks
Implement NativeAdCallback to receive results:
interface NativeAdCallback {
fun onNativeAdsReceivedSuccessful(ads: List<AppnextNativeApp>)
fun onNativeAdsReceivedError(error: AppnextError)
}
Updated about 3 hours ago