Using ContextSDK with Purchasely
Learn how to use ContextSDK with Purchasely 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 Purchasely
class OnboardingViewController: UIViewController {
func showPaywall() {
// 1. Capture the user's real-world context
let context = ContextManager.instantContext(flowName: "purchasely_onboarding", duration: 3)
// 2. Set the context as a Purchasely user attribute
Purchasely.setUserAttribute(withBoolValue: context.shouldUpsell, forKey: "context_should_upsell")
// 3. Load and show the Purchasely paywall
let paywallController = Purchasely.presentationController(
for: "onboarding",
loaded: { [weak self] controller, success, error in
if let controller = controller, success {
self?.present(controller, animated: true)
} else if let error = error {
print("Failed to load paywall: \(error)")
context.log(.skipped)
}
},
completion: { result, _ in
// 4. Log the outcome to help train the ML model
switch result {
case .purchased:
context.log(.positive)
case .cancelled:
context.log(.negative)
case .restored:
context.log(.skipped)
@unknown default:
context.log(.skipped)
}
}
)
}
}Step 2: Configure Purchasely Rules
Understanding the Flow
Logging Revenue Outcomes
Best Practices
Choose a Flow Name
Always Log Outcomes
Handle Multiple Placements
Placement Naming Convention
Related Documentation
Last updated
Was this helpful?