Superwall

PaywallPresentationHandler

Handles events related to paywall presentation.

Deprecated SDK

We strongly recommend migrating to the new Superwall Expo SDK, see our migration guide for details.

Purpose

Handles events related to paywall presentation. Use this to receive callbacks about the paywall lifecycle when registering a placement.

Signature

export class PaywallPresentationHandler {
  onPresentHandler?: (info: PaywallInfo) => void
  onDismissHandler?: (info: PaywallInfo, result: PaywallResult) => void
  onErrorHandler?: (error: string) => void
  onSkipHandler?: (reason: PaywallSkippedReason) => void

  onPresent(handler: (info: PaywallInfo) => void): void
  onDismiss(handler: (info: PaywallInfo, result: PaywallResult) => void): void
  onError(handler: (error: string) => void): void
  onSkip(handler: (reason: PaywallSkippedReason) => void): void
}

Methods

MethodParametersDescription
onPresenthandler: (info: PaywallInfo) => voidSets a handler that is called when a paywall is presented.
onDismisshandler: (info: PaywallInfo, result: PaywallResult) => voidSets a handler that is called when a paywall is dismissed.
onErrorhandler: (error: string) => voidSets a handler that is called when an error occurs during paywall presentation.
onSkiphandler: (reason: PaywallSkippedReason) => voidSets a handler that is called when a paywall is skipped (not shown).

Usage

Create a handler and use it when registering a placement:

import { PaywallPresentationHandler, PaywallResult, PaywallSkippedReason } from "@superwall/react-native-superwall"

const handler = new PaywallPresentationHandler()

handler.onPresent((info) => {
  console.log("Paywall presented:", info.name)
  // Pause video, hide UI, etc.
  pauseBackgroundTasks()
})

handler.onDismiss((info, result: PaywallResult) => {
  console.log("Paywall dismissed with result:", result.type)
  // Resume video, show UI, etc.
  resumeBackgroundTasks()
  
  if (result.type === "purchased") {
    console.log("User purchased!")
  } else if (result.type === "declined") {
    console.log("User dismissed without purchasing")
  } else if (result.type === "restored") {
    console.log("User restored a purchase")
  }
})

handler.onError((error) => {
  console.error("Paywall error:", error)
  // Handle error
})

handler.onSkip((reason) => {
  console.log("Paywall skipped:", reason)
  // Handle skip reason
})

// Use the handler when registering
Superwall.shared.register({
  placement: "premium_feature",
  handler: handler,
  feature: () => {
    // Feature code
  }
})

Handler Callbacks

  • onPresent: Called when a paywall is successfully presented to the user.
  • onDismiss: Called when a paywall is dismissed. The result parameter has a type of purchased, declined, or restored.
  • onError: Called when an error occurs during paywall presentation or loading.
  • onSkip: Called when a paywall is skipped (not shown) for various reasons (user already subscribed, no audience match, etc.).

How is this guide?

Edit on GitHub