| Select platform: | iOS+ Android Unity |
In-app purchases (IAP) are digital content or features that you can sell in a mobile app through Google Play 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.
In most cases, the Analytics SDK automatically collects IAP events without requiring API calls in your app. In addition, here are some additional options for collecting IAP events:
You can manually log in-app purchase events from your app directly, without interacting with the Play Store.
You can also log IAP events manually in a WebView.
This guide explains how to set up your project for automatic tracking, and 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.
Make sure that you're using the latest SDK:
- For automatic in-app purchase tracking: Make sure that your app is using the Analytics SDK v17.3.0+ (or Firebase Android BoM v25.2.0+).
- For manual in-app purchase tracking: Make sure that your app is using the Analytics SDK v23.2.0+ (or Firebase Android BoM v34.10.0+)
Implementation
In most cases, the Analytics SDK automatically logs IAP events without requiring additional code.
For Android apps, you can measure IAP events as soon as you link to Google Play.
If you need to track in-app purchases made outside of the Play Store, you can log IAP events manually using the following code snippet or in a WebView.
To manually track in-app purchases, make sure that you're using Analytics SDK v23.2.0+ (or Firebase Android BoM v34.10.0+).
Kotlin
import android.os.Bundle
import com.google.firebase.analytics.FirebaseAnalytics
class MyClass(val analytics: FirebaseAnalytics) {
...
fun logInAppPurchaseEvent(itemName: String, value: Double, currency: String) {
val params = Bundle()
params.putString(FirebaseAnalytics.Param.ITEM_NAME, itemName)
params.putDouble(FirebaseAnalytics.Param.VALUE, value)
params.putString(FirebaseAnalytics.Param.CURRENCY, currency)
analytics.logEvent(FirebaseAnalytics.Event.IN_APP_PURCHASE, params)
}
}
Java
import android.os.Bundle;
import com.google.firebase.analytics.FirebaseAnalytics;
public class MyClass {
private FirebaseAnalytics analytics;
...
public void logInAppPurchaseEvent(String itemName, Double value, String currency) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.ITEM_NAME, itemName);
params.putDouble(FirebaseAnalytics.Param.VALUE, value);
params.putString(FirebaseAnalytics.Param.CURRENCY, currency);
analytics.logEvent(FirebaseAnalytics.Event.IN_APP_PURCHASE, params);
}
}