Skip to main content

Setting up an Ad Placement - Compose

The SDK supports Banner Ads, via the CIBannerView Composable function. This takes up to three parameters:

Required

  • placementID: String: Unique ID for this Ad Placement provided by Content Ignite.
  • pageUrl: String?: This is used for targeting for example if the ad is displayed inline within an article or section of the app which has an equivalent URL on the web.

Optional

  • eventListener: CIBannerEventListener: Interface which enables you to respond to events related to the banner ad.
  • targeting: Map<String, List<String>>: Pass custom key-value pairs to ad requests.
  • modifier: Modifier used to set the size of the ad placement.
  • publisher: Composable function to allow you to provide a fallback to your existing Ad implementation for this particular placement. This gives publishers full control over the use of the SDK and the rate at which this fallback is used can be controlled directly through the Fusion platform.
import com.contentignite.mobilesdk.CIViews.CIBannerView

val eventListener = object : CIBannerEventListener {
    override fun bannerLoaded() {
        println("Banner ad loaded.")
    }

    override fun bannerLoadFailed(error: CIBannerLoadError) {
        println("Banner ad failed to load: $error")
    }

    override fun bannerClicked() {
        println("Banner ad clicked.")
    }

    override fun bannerImpression() {
        println("Banner ad impression.")
    }
}

CIBannerView(
    placementID = "<PLACEMENT-ID>",
    pageUrl = "https://publisher.com/sport",
    eventListener = eventListener,
    targeting = mapOf("segment" to listOf("health", "fitness")),
    modifier =
        Modifier
            .fillMaxSize()
            .height(50.dp),
    publisher = {
        // Publisher fallback implementation
    }
)