KontextAds.createSession(...)
Session configured from the given SessionOptions. Fires /init in the background. Pass context.applicationContext so the session is not tied to any single Activity.
SessionOptions
Stable identifier for the end user. Used for personalization, frequency capping, and rewarded ads.
Privacy / consent signals. TCF (
gdpr / gdprConsent) is collected automatically if a TCF-compliant CMP is integrated — set manually only for COPPA, GPP, or US Privacy.Optional diagnostic stream — fires for every internal SDK event (preload start/end, iframe lifecycle, geometry updates, etc.). Useful during integration. Leave null in production.
Session
Append a When
Message to the conversation. Synchronous (not suspend). User messages trigger a debounced preload; assistant messages let the SDK link the matched ad to the placement.trackOnly = true, the preload is sent for analytics but no ad is generated.Returns an
Ad for the given messageId. Idempotent — repeated calls with the same messageId + code + theme return the same Ad. Cache the result.Live-update preload-scoped fields. See Guides → Live-updating session options.
Tear down the session: cancel preloads, destroy ads, release WebView resources. Idempotent.
close() is an alias (implements AutoCloseable).Hot Flow that delivers the same events as
onEvent. Useful for ViewModels and coroutine pipelines.true if the server has permanently disabled the session via the /init response (e.g. geo-restriction). Subsequent preloads are skipped.MutablePublisherOptions
Subset of SessionOptions accepted by session.updateOptions(...). Every field is optional — non-null overwrites, null leaves unchanged.
Message
AdOptions
AddMessageOptions
When
true, the preload is still sent (for analytics) but no ad is generated for this message. Defaults to false.UI
InlineAd (Compose, recommended)
messageId. Internally calls session.createAd(...), attaches a pooled WebView, and reports container geometry back to the iframe. Safe to compose in a LazyColumn — the underlying Ad and WebView survive recomposition and scroll-off-screen recycling.
A second overload accepts a pre-resolved Ad directly:
InlineAdView (View interop)
bind(messageId, session) once after inflating; observe onHeightChange to resize the surrounding container (e.g. in a RecyclerView row).
AdEvent
AdEvent is a sealed class with one typed payload per case. Every case has a stable string identifier accessible via event.name.
AdEvent.Filled — wire name ad.filled
An ad was returned and linked to the placement.
AdEvent.NoFill — wire name ad.no-fill
No ad was returned for the placement (server skipped).
AdEvent.AdHeight — wire name ad.height
The ad iframe reported a new height. Use to size the surrounding container in RecyclerView rows. The InlineAd Compose composable handles this for you automatically.