Superwall

getPresentationResult()

Check the outcome of a placement without presenting a paywall.

Purpose

Retrieves the presentation result for a placement without presenting the paywall. Call this when you need to know whether a placement would show a paywall, send the user to a holdout, or fail due to missing configuration before you decide how to render UI.

Signature

suspend fun Superwall.getPresentationResult(
  placement: String,
  params: Map<String, Any>? = null,
): Result<PresentationResult>
fun Superwall.getPresentationResultSync(
  placement: String,
  params: Map<String, Any>? = null,
): Result<PresentationResult>

getPresentationResultSync blocks the calling thread. Prefer the suspend function inside a coroutine whenever possible.

Parameters

NameTypeDescription
placementStringThe placement to evaluate.
paramsMap<String, Any>?Optional custom parameters that feed audience filters. Keys starting with $ are dropped by the SDK. Nested maps or lists are ignored. Defaults to null.

Returns / State

Returns a Kotlin Result<PresentationResult>.

  • On success, the wrapped PresentationResult can be:
    • PresentationResult.PlacementNotFound – Placement is missing from any live campaign.
    • PresentationResult.NoAudienceMatch – No audience matched, so nothing would show.
    • PresentationResult.Paywall(experiment) – A paywall would be presented; inspect the experiment.
    • PresentationResult.Holdout(experiment) – The user is in a holdout group for that experiment.
    • PresentationResult.PaywallNotAvailable – The SDK could not present (no activity, already showing, offline, etc.).
  • On failure, the Result contains the thrown exception (for example, the SDK is not configured yet). Inspect it with exceptionOrNull() or onFailure.

Usage

lifecycleScope.launch {
  val result = Superwall.instance.getPresentationResult(
    placement = "premium_feature",
    params = mapOf("source" to "settings")
  )

  result
    .onSuccess { presentation ->
      when (presentation) {
        is PresentationResult.Paywall -> {
          logExperiment(presentation.experiment)
          showLockedState()
        }
        is PresentationResult.Holdout -> showHoldoutBanner()
        is PresentationResult.NoAudienceMatch -> unlockFeature()
        is PresentationResult.PlacementNotFound -> Timber.w("Missing placement configuration")
        is PresentationResult.PaywallNotAvailable -> showOfflineMessage()
      }
    }
    .onFailure { error ->
      Timber.e(error, "Unable to fetch presentation result")
    }
}
// Blocking usage (for example, inside a worker)
val result = Superwall.instance.getPresentationResultSync("premium_feature")
val presentation = result.getOrNull() ?: return

How is this guide?

Edit on GitHub