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.
Analytics shows IAP events in the In-app purchases report.
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.
Before you begin
Set up your Firebase project and your app's codebase as described in Get Started with Google Analytics.
Link your Firebase project to a Google Analytics 4 property.
For Apple platform apps:
- Make sure that your app is using the Analytics SDK v6.20.0+.
For Android apps:
- Make sure that your app is using the Analytics SDK v17.3.0+ (or Firebase Android BoM v25.2.0+).
- Link your Firebase apps to Google Play.
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.
import StoreKit import FirebaseAnalytics // A user tapped a button to purchase an item. func userTappedPurchaseUpgradeButton() { let product = ... purchaseSomeProduct(product) } func purchaseSomeProduct(_ product: Product) { // Purchase a Product. This is mostly standard boilerplate StoreKit 2 // code, except for the Analytics.logTransaction() call. let result = try await product.purchase() switch result { case .success(let verification): let transaction = try checkVerified(verification) // Call this Firebase API to log the in-app purchase event. Analytics.logTransaction(transaction) await transaction.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.
Kotlin+KTX
To log IAP events, link to Google Play.
Java
To log IAP events, link to Google Play.