Stay organized with collections
Save and categorize content based on your preferences.
In-app purchases (IAP) are digital content or features that you can sell in a
mobile app through Google Play or the Apple App Store so your app doesn't
have to process financial transactions. Examples of in-app purchases include
subscription-based content or special game pieces.
For Android apps, the Analytics SDK integrates with Google Play. For Apple
platform apps, the SDK integrates with the Apple App Store using the
StoreKit 1 and StoreKit 2 APIs from Apple.
In most cases, the Analytics SDK automatically collects IAP events without
requiring API calls in your app. This guide explains how to set up your project
for automatic tracking, and it describes some special cases that require a few
lines of code to implement.
If you're developing an Android app, you can measure IAP events as soon as you
link to Google Play. The remainder of this guide is focused on Apple platform
apps.
If you're an Apple developer, make sure you're familiar with the Apple StoreKit
1 and StoreKit 2 in-app purchase APIs by reviewing the
Apple documentation.
Implementation
Swift
If you're using StoreKit 1, the Analytics SDK automatically logs
IAP events.
If you're using StoreKit 2, use the following code to log IAP events.
importStoreKitimportFirebaseAnalytics// A user tapped a button to purchase an item.funcuserTappedPurchaseUpgradeButton(){letproduct=...purchaseSomeProduct(product)}funcpurchaseSomeProduct(_product:Product){// Purchase a Product. This is mostly standard boilerplate StoreKit 2// code, except for the Analytics.logTransaction() call.letresult=tryawaitproduct.purchase()switchresult{case.success(letverification):lettransaction=trycheckVerified(verification)// Call this Firebase API to log the in-app purchase event.Analytics.logTransaction(transaction)awaittransaction.finish()...}
Objective-C
If you're using StoreKit 1, the Analytics SDK automatically logs
IAP events.
StoreKit 2 is Swift-only, so an Objective-C implementation is not supported.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-15 UTC."],[],[],null,["In-app purchases (IAP) are digital content or features that you can sell in a\nmobile app through Google Play or the Apple App Store so your app doesn't\nhave to process financial transactions. Examples of in-app purchases include\nsubscription-based content or special game pieces.\n\nAnalytics shows IAP events in the\n[In-app purchases report](https://support.google.com/analytics/answer/12923440).\n\nFor Android apps, the Analytics SDK integrates with Google Play. For Apple\nplatform apps, the SDK integrates with the Apple App Store using the\nStoreKit 1 and StoreKit 2 APIs from Apple.\n\nIn most cases, the Analytics SDK automatically collects IAP events without\nrequiring API calls in your app. This guide explains how to set up your project\nfor automatic tracking, and it describes some special cases that require a few\nlines of code to implement.\n\nBefore you begin\n\n- Set up your Firebase project and your app's codebase as described in\n [Get Started with Google Analytics](/docs/analytics/get-started).\n\n- [Link your Firebase project to a Google Analytics 4 property.](https://support.google.com/firebase/answer/9289399)\n\n- For Apple platform apps:\n\n - Make sure that your app is using the Analytics SDK v6.20.0+.\n- For Android apps:\n\n - Make sure that your app is using the Analytics SDK v17.3.0+ (or Firebase Android BoM v25.2.0+).\n - [Link your Firebase apps to Google Play](https://support.google.com/firebase/answer/6392038).\n\nIf you're developing an Android app, you can measure IAP events as soon as you\nlink to Google Play. The remainder of this guide is focused on Apple platform\napps.\n\nIf you're an Apple developer, make sure you're familiar with the Apple StoreKit\n1 and StoreKit 2 in-app purchase APIs by reviewing the\n[Apple documentation](https://developer.apple.com/documentation/storekit/in-app_purchase).\n\nImplementation \n\nSwift\n\nIf you're using StoreKit 1, the Analytics SDK automatically logs\nIAP events.\n\nIf you're using StoreKit 2, use the following code to log IAP events. \n\n```swift\nimport StoreKit\nimport FirebaseAnalytics\n\n// A user tapped a button to purchase an item.\nfunc userTappedPurchaseUpgradeButton() {\n let product = ...\n purchaseSomeProduct(product)\n}\n\nfunc purchaseSomeProduct(_ product: Product) {\n // Purchase a Product. This is mostly standard boilerplate StoreKit 2\n // code, except for the Analytics.logTransaction() call.\n let result = try await product.purchase()\n switch result {\n case .success(let verification):\n let transaction = try checkVerified(verification)\n\n // Call this Firebase API to log the in-app purchase event.\n Analytics.logTransaction(transaction)\n\n await transaction.finish()\n ...\n}\n```\n\nObjective-C\n\nIf you're using StoreKit 1, the Analytics SDK automatically logs\nIAP events.\n\nStoreKit 2 is Swift-only, so an Objective-C implementation is not supported.\n\nKotlin\n\nTo log IAP events,\n[link to Google Play](//support.google.com/firebase/answer/6392038).\n\nJava\n\nTo log IAP events,\n[link to Google Play](//support.google.com/firebase/answer/6392038)."]]