Superwall

SuperwallDelegate

A class that handles Superwall lifecycle events and analytics.

Deprecated SDK

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

Set the delegate using Superwall.shared.setDelegate(delegate) to receive these callbacks.

Use handleSuperwallEvent(eventInfo) to track Superwall analytics events in your own analytics platform for a complete view of user behavior.

SuperwallDelegate is an abstract class—all methods are required. Provide no-op implementations for callbacks you do not use.

Purpose

Provides callbacks for Superwall lifecycle events, analytics tracking, and custom paywall interactions.

Signature

export abstract class SuperwallDelegate {
  abstract subscriptionStatusDidChange(from: SubscriptionStatus, to: SubscriptionStatus): void
  abstract willRedeemLink(): void
  abstract didRedeemLink(result: RedemptionResult): void
  abstract handleSuperwallEvent(eventInfo: SuperwallEventInfo): void
  abstract handleCustomPaywallAction(name: string): void
  abstract willDismissPaywall(paywallInfo: PaywallInfo): void
  abstract willPresentPaywall(paywallInfo: PaywallInfo): void
  abstract didDismissPaywall(paywallInfo: PaywallInfo): void
  abstract didPresentPaywall(paywallInfo: PaywallInfo): void
  abstract paywallWillOpenURL(url: URL): void
  abstract paywallWillOpenDeepLink(url: URL): void
  abstract handleLog(
    level: string,
    scope: string,
    message?: string,
    info?: Map<string, any>,
    error?: string
  ): void
}

Methods

All methods must be implemented (you can provide empty bodies). Key methods include:

Prop

Type

Usage

Basic delegate setup:

import { SuperwallDelegate, PaywallInfo, SubscriptionStatus } from "@superwall/react-native-superwall"

class MyDelegate extends SuperwallDelegate {
  subscriptionStatusDidChange(from: SubscriptionStatus, to: SubscriptionStatus) {
    console.log(`Subscription changed from ${from.status} to ${to.status}`)
    // update UI here
  }
  
  handleSuperwallEvent(eventInfo: SuperwallEventInfo) {
    // Track in your analytics
    Analytics.track("superwall_event", {
      event: eventInfo.event.type,
      paywall_id: eventInfo.paywallInfo?.id
    })
  }
  
  handleCustomPaywallAction(name: string) {
    switch (name) {
      case "help":
        this.presentHelpScreen()
        break
      case "contact":
        this.presentContactForm()
        break
    }
  }
  
  willPresentPaywall(paywallInfo: PaywallInfo) {
    // Pause video, hide UI, etc.
    this.pauseBackgroundTasks()
  }
  
  didDismissPaywall(paywallInfo: PaywallInfo) {
    // Resume video, show UI, etc.
    this.resumeBackgroundTasks()
  }

  // Required methods you might not use
  willRedeemLink() {}
  didRedeemLink() {}
  handleCustomPaywallAction() {}
  willPresentPaywall() {}
  didPresentPaywall() {}
  paywallWillOpenURL() {}
  paywallWillOpenDeepLink() {}
  handleLog() {}
}

// Set the delegate
await Superwall.shared.setDelegate(new MyDelegate())

Track subscription status changes:

subscriptionStatusDidChange(from: SubscriptionStatus, to: SubscriptionStatus) {
  console.log("Subscription changed from", from, "to", to)
  this.updateUI(for: to)
}

Forward analytics events:

handleSuperwallEvent(eventInfo: SuperwallEventInfo) {
  switch (eventInfo.event.type) {
    case EventType.paywallOpen:
      Analytics.track("paywall_opened", {
        paywall_id: eventInfo.paywallInfo?.id,
        placement: eventInfo.placement
      })
      break
    case EventType.transactionComplete:
      Analytics.track("subscription_purchased", {
        product_id: eventInfo.product?.id,
        paywall_id: eventInfo.paywallInfo?.id
      })
      break
  }
}

How is this guide?

Edit on GitHub