KontextAds.createSession(_:)
Session configured from the given SessionOptions. Fires /init in the background.
SessionOptions
String
required
Your unique publisher token.
String
required
Stable identifier for the end user. Used for personalization, frequency capping, and rewarded ads.
String
required
Unique ID of the current conversation / chat thread.
[String]?
Placement codes to request ads for. Defaults to
["inlineAd"] when nil or empty.Character?
AI character metadata for contextual targeting.
String?
Publisher-defined cohort identifier (e.g. for A/B testing).
Regulatory?
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.String?
End-user email for frequency-cap deduplication.
String?
IDFA you collected yourself. Takes priority over the SDK’s automatic collection. Use with
requestTrackingAuthorization: false.String?
IDFV you collected yourself. Falls back to
UIDevice.current.identifierForVendor when nil.Bool
Whether the SDK should auto-request ATT authorization. Defaults to
true.(AdEvent) -> Void
Callback invoked on every ad lifecycle event. Called on the main thread.
Session
method
Append a When
Message to the conversation. Synchronous. User messages trigger a debounced preload.trackOnly: true, the preload is sent for analytics but no ad is generated.method
Returns an
Ad for the given messageId. Idempotent — repeated calls with the same messageId + placement code return the same Ad. Cache the result.method
Live-update preload-scoped fields. See Guides → Live-updating session options.
method
Tear down the session: cancel preloads, destroy ads, release web views. Idempotent.
AnyPublisher<AdEvent, Never>
Combine publisher delivering the same events as
onEvent. Useful for SwiftUI / Combine pipelines.[Message]
Read-only snapshot of messages tracked by the session.
UUID?
Server-assigned session ID.
nil until the first successful preload.Bool
true if the server has permanently disabled the session via the /init response (e.g. geo-restriction). Subsequent preloads are skipped.Bool
true after destroy() is called.MutablePublisherOptions
Subset of SessionOptions accepted by session.updateOptions(_:). Every field is optional — non-nil overwrites, nil leaves unchanged.
String?
Regulatory?
String?
String?
String?
Message
String
required
Unique message ID.
Message.Role
required
.user or .assistant.String
required
Message text.
Date
Defaults to
Date().AdOptions
String
Placement code. Defaults to
"inlineAd".String?
UI theme hint forwarded to the ad iframe (e.g.
"dark").AddMessageOptions
Bool
When
true, the preload is still sent (for analytics) but no ad is generated for this message. Defaults to false.AdEvent
AdEvent is an enum with one typed payload per case. Every case has a stable string identifier accessible via event.name.
.filled(FilledData) — wire name ad.filled
An ad was returned and linked to the placement.
.noFill(NoFillData) — wire name ad.no-fill
No ad was returned for the placement (server skipped).
.adHeight(AdHeightData) — wire name ad.height
The ad iframe reported a new height. Use to size the surrounding container (especially in UIKit UITableView / UICollectionView cells).