> Documentation index: https://firebase.google.com/docs/analytics/llms.txt

|---|---|
| **Select platform:** | [iOS+](https://firebase.google.com/docs/analytics/ios/measure-in-app-purchases.md.txt) [Android](https://firebase.google.com/docs/analytics/android/measure-in-app-purchases.md.txt) [Unity](https://firebase.google.com/docs/analytics/unity/measure-in-app-purchases.md.txt) |

<br />

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](https://support.google.com/analytics/answer/12923440).

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](https://firebase.google.com/docs/analytics/android/get-started.md.txt).

- [Link your Firebase project to a Google Analytics 4 property.](https://support.google.com/firebase/answer/9289399)

- 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+).

  > [!NOTE]
  > **Note:** For Android apps, you can measure IAP events as soon as you link to Google Play.

  - 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+)
- [Link your Firebase apps to Google Play](https://support.google.com/firebase/answer/6392038).

## 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](https://support.google.com/analytics/answer/11548051).

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](https://firebase.google.com/docs/analytics/webview.md.txt?platform=android#log-in-app-purchase-events-manually-in-a-webview-on-android).

> [!NOTE]
> **Note:** In-app purchases will continue to be logged automatically for purchases completed through the Play Store, and the SDK won't de-duplicate any manually logged in-app purchases.

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

```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

```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);
  }
}
```