Using ContextSDK with Superwall
Learn how to use ContextSDK with Superwall to optimize paywall timing and log conversion revenue from in-app purchases.
How it works
Integration Guide
Step 1: Capture Context and Show Paywall
import ContextSDK
import SuperwallKit
class OnboardingViewController: UIViewController {
func showPaywall() {
// 1. Capture the user's context
let context = ContextManager.instantContext(flowName: "superwall_onboarding_step", duration: 3)
// 2. Create handler for paywall callbacks
let handler = PaywallPresentationHandler()
handler.onDismiss { paywallInfo, result in
switch result {
case .purchased(let product):
// User completed a purchase
context.logRevenueOutcome(from: product)
case .declined:
// User declined the paywall by pressing close button
context.log(.negative)
case .restored:
// User restored their purchases
context.log(.skipped)
default:
context.log(.skipped)
}
}
handler.onSkip { reason in
// Paywall was skipped (no paywall configured, user already subscribed, etc.)
context.log(.skipped)
}
// 3. Register Superwall placement with context
Superwall.shared.register(
placement: "onboarding_step",
params: ["contextGoodMoment": context.shouldUpsell],
handler: handler
)
}
}Step 2: Use Context in Superwall Rules
Best Practices
Choose a Flow Name
Always Log Outcomes
Handle Multiple Placements
Related Documentation
Last updated
Was this helpful?