# SuperwallDelegate

A class that handles Superwall lifecycle events and analytics.

> **Warning**

**Deprecated SDK**We strongly recommend migrating to the new [Superwall Expo SDK](/docs/expo), see our [migration guide](/docs/expo/guides/migrating-react-native) for details.



> **Note**

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



> **Tip**

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



> **Warning**

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



Purpose [#purpose]

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

Signature [#signature]

```typescript
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 [#methods]

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

<TypeTable
  type="{
  subscriptionStatusDidChange: {
    type: &#x22;from: SubscriptionStatus, to: SubscriptionStatus&#x22;,
    description: &#x22;Called when subscription status changes.&#x22;,
    required: true,
  },
  handleSuperwallEvent: {
    type: &#x22;eventInfo: SuperwallEventInfo&#x22;,
    description: &#x22;Called for all internal analytics events. Use for tracking in your own analytics.&#x22;,
    required: true,
  },
  handleCustomPaywallAction: {
    type: &#x22;name: string&#x22;,
    description: &#x22;Called when user taps elements with `data-pw-custom` tags.&#x22;,
    required: true,
  },
  willPresentPaywall: {
    type: &#x22;paywallInfo: PaywallInfo&#x22;,
    description: &#x22;Called before paywall presentation.&#x22;,
    required: true,
  },
  didPresentPaywall: {
    type: &#x22;paywallInfo: PaywallInfo&#x22;,
    description: &#x22;Called after paywall presentation.&#x22;,
    required: true,
  },
  willDismissPaywall: {
    type: &#x22;paywallInfo: PaywallInfo&#x22;,
    description: &#x22;Called before paywall dismissal.&#x22;,
    required: true,
  },
  didDismissPaywall: {
    type: &#x22;paywallInfo: PaywallInfo&#x22;,
    description: &#x22;Called after paywall dismissal.&#x22;,
    required: true,
  },
  paywallWillOpenURL: {
    type: &#x22;url: URL&#x22;,
    description: &#x22;Called when paywall attempts to open a URL.&#x22;,
    required: true,
  },
  paywallWillOpenDeepLink: {
    type: &#x22;url: URL&#x22;,
    description: &#x22;Called when paywall attempts to open a deep link.&#x22;,
    required: true,
  },
  handleLog: {
    type: &#x22;level: string, scope: string, message?: string, info?: Map<string, any>, error?: string&#x22;,
    description: &#x22;Called for logging messages from the SDK.&#x22;,
    required: true,
  },
  willRedeemLink: {
    type: &#x22;None&#x22;,
    description: &#x22;Called before the SDK attempts to redeem a promotional link.&#x22;,
    required: true,
  },
  didRedeemLink: {
    type: &#x22;result: RedemptionResult&#x22;,
    description: &#x22;Called after the SDK has attempted to redeem a promotional link.&#x22;,
    required: true,
  },
}"
/>

Usage [#usage]

Basic delegate setup:

```typescript
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:

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

Forward analytics events:

```typescript
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
  }
}
```