SuperwallDelegate
A protocol that handles Superwall lifecycle events and analytics.
Set the delegate using Superwall.shared.delegate = self
to receive these callbacks.
Use handleSuperwallEvent(withInfo:)
to track Superwall analytics events in your own analytics platform for a complete view of user behavior.
Purpose
Provides callbacks for Superwall lifecycle events, analytics tracking, and custom paywall interactions.
Signature
public protocol SuperwallDelegate: AnyObject {
@MainActor
func subscriptionStatusDidChange(
from oldValue: SubscriptionStatus,
to newValue: SubscriptionStatus
)
@MainActor
func handleSuperwallEvent(withInfo eventInfo: SuperwallEventInfo)
@MainActor
func handleCustomPaywallAction(withName name: String)
@MainActor
func willDismissPaywall(withInfo paywallInfo: PaywallInfo)
@MainActor
func willPresentPaywall(withInfo paywallInfo: PaywallInfo)
@MainActor
func didDismissPaywall(withInfo paywallInfo: PaywallInfo)
@MainActor
func didPresentPaywall(withInfo paywallInfo: PaywallInfo)
@MainActor
func paywallWillOpenURL(url: URL)
@MainActor
func paywallWillOpenDeepLink(url: URL)
@MainActor
func handleLog(
level: LogLevel,
scope: LogScope,
message: String,
info: [String: Any]?,
error: Error?
)
}
Parameters
All methods are optional to implement. Key methods include:
Method | Parameters | Description |
---|---|---|
subscriptionStatusDidChange | oldValue , newValue | Called when subscription status changes. |
handleSuperwallEvent | eventInfo | Called for all internal analytics events. Use for tracking in your own analytics. |
handleCustomPaywallAction | name | Called when user taps elements with data-pw-custom tags. |
willPresentPaywall | paywallInfo | Called before paywall presentation. |
didPresentPaywall | paywallInfo | Called after paywall presentation. |
willDismissPaywall | paywallInfo | Called before paywall dismissal. |
didDismissPaywall | paywallInfo | Called after paywall dismissal. |
Returns / State
All delegate methods return Void
. They provide information about Superwall events and state changes.
Usage
Basic delegate setup:
class ViewController: UIViewController, SuperwallDelegate {
override func viewDidLoad() {
super.viewDidLoad()
Superwall.shared.delegate = self
}
}
Track subscription status changes:
func subscriptionStatusDidChange(
from oldValue: SubscriptionStatus,
to newValue: SubscriptionStatus
) {
print("Subscription changed from \(oldValue) to \(newValue)")
updateUI(for: newValue)
}
Forward analytics events:
func handleSuperwallEvent(withInfo eventInfo: SuperwallEventInfo) {
switch eventInfo.event {
case .paywallOpen(let info):
Analytics.track("paywall_opened", properties: [
"paywall_id": info.id,
"placement": info.placement
])
case .transactionComplete(let transaction, let product, _, let info):
Analytics.track("subscription_purchased", properties: [
"product_id": product.id,
"paywall_id": info.id
])
default:
break
}
}
Handle custom paywall actions:
func handleCustomPaywallAction(withName name: String) {
switch name {
case "help":
presentHelpScreen()
case "contact":
presentContactForm()
default:
print("Unknown custom action: \(name)")
}
}
Handle paywall lifecycle:
func willPresentPaywall(withInfo paywallInfo: PaywallInfo) {
// Pause video, hide UI, etc.
pauseBackgroundTasks()
}
func didDismissPaywall(withInfo paywallInfo: PaywallInfo) {
// Resume video, show UI, etc.
resumeBackgroundTasks()
}
How is this guide?