Skip to content

NativeAdSlot

Displays a contextually targeted native ad inline within your Compose UI. The slot auto-sizes to the creative height and collapses to zero when no ad is available.

Native ad slot displayed inline within a mobile app feed

Basic Usage

kotlin
import ad.simula.ad.sdk.nativead.NativeAdSlot

@Composable
fun CharacterFeed(characters: List<Character>) {
    LazyColumn {
        itemsIndexed(characters) { index, character ->
            CharacterCard(character)
            if (index % 10 == 9) {
                NativeAdSlot(
                    adUnitId = "SIM-NAT-XXXXXXXX",
                    onImpression = { data ->
                        Log.d("SimulaAd", "Impression: ${data.impressionId}")
                    }
                )
            }
        }
    }
}

Parameters

ParameterTypeDefaultDescription
adUnitIdString?nullAd unit ID from the publisher dashboard. Used for measurement and improved targeting
widthAny?fills parentWidth: Int/Float for dp, String with % or px suffix (e.g. "80%", "320px"). Min 300 dp
themeString?null"dark", "light", or "system". null uses the SDK default
modifierModifierModifierStandard Compose modifier for margins, padding, etc.
preloadedAdIdString?nullID from SimulaAds.preloadNativeAd() to render a cached ad instantly
onImpression(NativeAdData) -> Unit{}Fires when the ad is >=50% visible for >=1 second
onClick() -> Unit{}Fires when the user taps the ad CTA
onPaid(AdValue) -> Unit{}Estimated per-impression revenue, co-timed with onImpression. See AdValue
onError(NativeAdError) -> Unit{}Fires on load or render failure

Preloading

Preload ads before they scroll into view for instant rendering:

kotlin
// Preload
val preloadedId = SimulaAds.preloadNativeAd(
    adUnitId = "SIM-NAT-XXXXXXXX",
    theme = "system"
)

// Use in composable
NativeAdSlot(
    adUnitId = "SIM-NAT-XXXXXXXX",
    preloadedAdId = preloadedId
)

// Clean up if the ad was never displayed
SimulaAds.destroyPreloadedAd(preloadedId)

Invalidation

Force-refresh a specific slot or clear all cached native ads:

kotlin
// Refresh one slot
SimulaAds.invalidateNativeAd(adUnitId = "SIM-NAT-XXXXXXXX")

// Clear all cached native ads
SimulaAds.invalidateNativeAds()