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?
)
@MainActor
func customerInfoDidChange(
from oldValue: CustomerInfo,
to newValue: CustomerInfo
)
@MainActor
func userAttributesDidChange(newAttributes: [String: Any])
}Parameters
All methods are optional to implement. Key methods include:
Prop
Type
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
])
case .permissionGranted(let permission, let paywallId):
Analytics.track("permission_granted", properties: [
"permission": permission,
"paywall_id": paywallId
])
case .permissionDenied(let permission, let paywallId):
Analytics.track("permission_denied", properties: [
"permission": permission,
"paywall_id": paywallId
])
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()
}Handle customer info changes:
func customerInfoDidChange(
from oldValue: CustomerInfo,
to newValue: CustomerInfo
) {
// Check if user gained or lost subscriptions
let oldSubscriptionCount = oldValue.subscriptions.count
let newSubscriptionCount = newValue.subscriptions.count
if newSubscriptionCount > oldSubscriptionCount {
print("User gained a new subscription")
}
// Update purchase history UI
updatePurchaseHistoryUI(with: newValue)
}
func userAttributesDidChange(newAttributes: [String: Any]) {
// React to server-driven or paywall-triggered updates
refreshProfileUI(with: newAttributes)
}How is this guide?
Edit on GitHub