3rd Party Analytics (Legacy)
Superwall can easily be integrated with 3rd party analytics tools.
Hooking up Superwall events to 3rd party tools
SuperwallKit automatically tracks some internal events. You can view the list of events here. We encourage you to also track them in your own analytics by implementing the Superwall delegate. Using the handleSuperwallEvent(withInfo:)
function, you can forward events to your analytics service:
extension SuperwallService: SuperwallDelegate {
func handleSuperwallEvent(withInfo eventInfo: SuperwallEventInfo) {
print("analytics event called", eventInfo.event.description)
MyAnalyticsService.shared.track(
event: eventInfo.event.description,
params: eventInfo.params
)
}
}
Alternatively, if you want typed versions of all these events with associated values, you can access them via eventInfo.event
:
func handleSuperwallEvent(withInfo eventInfo: SuperwallEventInfo) {
switch eventInfo.event {
case .firstSeen:
break
case .appOpen:
break
case .appLaunch:
break
case .appInstall:
break
case .sessionStart:
break
case .appClose:
break
case .deepLink(let url):
break
case .triggerFire(let eventName, let result):
break
case .paywallOpen(let paywallInfo):
break
case .paywallClose(let paywallInfo):
break
case .transactionStart(let product, let paywallInfo):
break
case .transactionFail(let error, let paywallInfo):
break
case .transactionAbandon(let product, let paywallInfo):
break
case .transactionComplete(let transaction, let product, let paywallInfo):
break
case .subscriptionStart(let product, let paywallInfo):
break
case .freeTrialStart(let product, let paywallInfo):
break
case .transactionRestore(let paywallInfo):
break
case .userAttributes(let attributes):
break
case .nonRecurringProductPurchase(let product, let paywallInfo):
break
case .paywallResponseLoadStart(let triggeredEventName):
break
case .paywallResponseLoadNotFound(let triggeredEventName):
break
case .paywallResponseLoadFail(let triggeredEventName):
break
case .paywallResponseLoadComplete(let triggeredEventName, let paywallInfo):
break
case .paywallWebviewLoadStart(let paywallInfo):
break
case .paywallWebviewLoadFail(let paywallInfo):
break
case .paywallWebviewLoadComplete(let paywallInfo):
break
case .paywallWebviewLoadTimeout(let paywallInfo):
break
case .paywallProductsLoadStart(let triggeredEventName, let paywallInfo):
break
case .paywallProductsLoadFail(let triggeredEventName, let paywallInfo):
break
case .paywallProductsLoadComplete(let triggeredEventName):
break
case .subscriptionStatusDidChange:
break
}
}
Using events to see purchased products
If your goal is simply to view which product was purchased from a paywall, you don't need a purchase controller for that (though it can be done in one). Using a SuperwallDelegate
, you can leverage the transactionComplete
event, which provides direct access to the purchased product via product
:
import SwiftUI
import SuperwallKit
class SWDelegate: SuperwallDelegate {
func handleSuperwallEvent(withInfo eventInfo: SuperwallEventInfo) {
switch eventInfo.event {
case .transactionComplete(let transaction, let product, let paywallInfo):
print("Converted from paywall: \(product.productIdentifier)")
default:
print("\(#function) - \(eventInfo.event)")
}
}
}
@main
struct AwesomeApp: App {
init() {
Superwall.configure(apiKey: "MY_API_KEY")
Superwall.shared.delegate = self.swDelegate
}
var body: some Scene {
WindowGroup {
ContentView()
.onAppear { Superwall.shared.register(event: "test_event") }
}
}
}
In that example, as soon as a user converts on a paywall, the product identifier will be printed to the console:
Converted from paywall: ex.someProduct.identifier
How is this guide?