Logging Revenue with StoreKit 1
Learn how to log conversion revenue from StoreKit 1 in-app purchases for iOS 14 and earlier support
Basic StoreKit 1 Integration
Using SKProduct
// When a purchase completes successfully
func userDidPurchase(product: SKProduct) {
if let context = ContextManager.recentContext(flowName: "upsell_premium") {
context.logStoreKit1RevenueOutcome(from: product)
}
}Using SKPaymentTransaction
// In your SKPaymentTransactionObserver
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch transaction.transactionState {
case .purchased:
handlePurchasedTransaction(transaction)
queue.finishTransaction(transaction)
case .restored:
handleRestoredTransaction(transaction)
queue.finishTransaction(transaction)
case .failed:
handleFailedTransaction(transaction)
queue.finishTransaction(transaction)
default:
break
}
}
}
private func handlePurchasedTransaction(_ transaction: SKPaymentTransaction) {
if let context = ContextManager.recentContext(flowName: "upsell_premium") {
// Get the product information if available
let productId = transaction.payment.productIdentifier
if let product = loadedProducts[productId] {
// Log with both transaction and product context
context.logStoreKit1RevenueOutcome(from: transaction, product: product)
} else {
// Log with transaction only
context.logStoreKit1RevenueOutcome(from: transaction)
}
}
}
private func handleFailedTransaction(_ transaction: SKPaymentTransaction) {
if let context = ContextManager.recentContext(flowName: "upsell_premium") {
context.log(.negative)
}
}Metadata Extracted from StoreKit 1
From SKProduct
From SKPaymentTransaction (additional)
Was this helpful?