---
id: "integrations/third-party-integrations/firebase-integration"
title: "Firebase"
description: "The Firebase integration is available to all users signed up after September '23, the legacy Starter and Pro plans, and Enterprise plans. If you're on a legacy Free plan and want to access this integration, migrate to our new pricing via your billing settings."
permalink: "/docs/integrations/third-party-integrations/firebase-integration"
slug: "firebase-integration"
version: "current"
original_source: "docs/integrations/third-party-integrations/firebase-integration.mdx"
---

> **AI agents:** This is the Markdown version of a RevenueCat documentation page. For the complete documentation index, see [llms.txt](https://www.revenuecat.com/docs/llms.txt).

:::success\[Pro Integration]
The Firebase integration is available to all users signed up after September '23, the legacy Starter and Pro plans, and Enterprise plans. If you're on a legacy Free plan and want to access this integration, migrate to our new pricing via your [billing settings](https://app.revenuecat.com/settings/billing).
:::

This extension uses Firebase services as your RevenueCat backend for in-app purchases on Apple App Store, Google Play Store, and Amazon Appstore to control access to premium content and sync customer purchase information to Firestore. For example, you might want to:

- Store purchase lifecycle events (e.g., trial starts, purchases, subscription renewals, billing issues) in Firestore and react to them.
- Store and update information about customers and their purchases in Firestore.
- Update information about customers' entitlements as Firebase Authentication [Custom Claims](https://firebase.google.com/docs/auth/admin/custom-claims).

This Firebase integration has 2 parts that can be used independently of each other: Google Analytics and Firebase Extension. The Google Analytics portion of this integration allows RevenueCat to send subscription lifecycle events to Firebase Analytics / Google Analytics. The Firebase Extension allows RevenueCat to store and update customer information in a Cloud Firestore collection and set custom claims on a user's auth token to check active entitlement status.

Each part of the integration requires additional setup, which you can see outlined in the table below.

| Integration        | What's required                                                                                                            |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| Google Analytics   | ✅ `$firebaseAppInstanceId` customer attribute <br> ❌ (optional, but highly recommended) Setting Firebase user identity |
| Firebase Extension | ✅ Setting Firebase user identity                                                                                          |

### Integration at a Glance

| Includes Revenue | Supports Negative Revenue | Sends Sandbox Events | Includes Customer Attributes | Sends Transfer Events | Optional Event Types |
| :--------------: | :-----------------------: | :------------------: | :--------------------------: | :-------------------: | :------------------: |
|        ✅        |            ❌             |          ✅          |              ❌              |          ✅           |          ❌          |

## 1. Set up Firebase services in your project

Before installing this extension, set up the following Firebase services in your Firebase project.

- (optional) [Cloud Firestore](https://firebase.google.com/docs/firestore) to store In-App Purchases & Subscriptions details.
  - Follow the steps in the [documentation](https://firebase.google.com/docs/firestore/quickstart#create) to create a Cloud Firestore database.
- (optional) [Firebase Authentication](https://firebase.google.com/docs/auth) to enable different sign-up options for your users to enable Custom Claims management.
  - Enable the sign-in methods in the [Firebase console](https://console.firebase.google.com/project/_/authentication/providers) that you want to offer your users.

:::warning\[Invalid API Version]
When connecting to Firebase, it's possible that you may see an error like:

"Invalid API Version", with a couple of different version numbers. This is fixed as part of an automatic upgrade process when installing the extension, and generally doesn't indicate there being an issue with your setup.
:::

## 2. Set Firebase User Identity in RevenueCat

You should make sure to use the Firebase UID as the RevenueCat app user ID when setting the Firebase user identity in RevenueCat. This step is optional, but highly recommended as a best practice for the Google Analytics portion of this integration. The Firebase Extension portion **requires** this step to be completed.

```swift
import FirebaseAuth
import RevenueCat

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    // Configure Purchases before Firebase
    Purchases.configure(withAPIKey: "public_sdk_key")
    Purchases.shared.delegate = self

    // Add state change listener for Firebase Authentication
    Auth.auth().addStateDidChangeListener { (auth, user) in

        if let uid = user?.uid {

            // identify Purchases SDK with new Firebase user
            Purchases.shared.logIn(uid, { (info, created, error) in
                if let error {
                    print("Sign in error: \(error.localizedDescription)")
                } else {
                    print("User \(uid) signed in")
                }
            })
        }
    }
    return true
}
```

## 3. Send analytics events to Google Analytics

In order to send subscriber lifecycle events to Google Analytics, you must set the `$firebaseAppInstanceId` as an Attribute for your Customers and enable the integration from the RevenueCat integration settings page.

### Set `$firebaseAppInstanceId` as a customer attribute

Please ensure you're getting the app instance ID from the [Firebase Analytics](https://firebase.google.com/docs/analytics/get-started) package.

```swift
import FirebaseAuth
import RevenueCat

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    // Configure Purchases before Firebase
    Purchases.configure(withAPIKey: "public_sdk_key")
    Purchases.shared.delegate = self

    // Set the reserved $firebaseAppInstanceId attribute from Firebase Analytics
    let instanceID = Analytics.appInstanceID()
    if let unwrapped = instanceID {
        print("Instance ID -> " + unwrapped)
        print("Setting Attributes")
        Purchases.shared.attribution.setFirebaseAppInstanceID(unwrapped)
    } else {
        print("Instance ID -> NOT FOUND!")
    }

    return true
}
```

:::warning
Setting an incorrect app instance ID will prevent events from displaying in Google Analytics.
:::

### Enable Google Analytics

You can "turn on" the integration from the RevenueCat dashboard.

1. Navigate to your project settings in the RevenueCat dashboard and choose 'Firebase' from the Integrations menu

![Integration setup](https://www.revenuecat.com/docs_images/integrations/setup-integrations.png)

2. Add your Firebase App ID and API secret for your iOS app and/or Android app

To set up your Firebase App ID, navigate to `Google Analytics > Admin > Data Streams > iOS/Android > Add Stream`. Open the App Stream to find your Firebase App ID. Copy and paste into the RevenueCat settings page.

![Data stream details page](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/data-stream-details.png)

To find your API secret, in the same *App stream details* page select "Measure Protocol API secrets". Create an API secret. Copy and paste into the RevenueCat settings page.

3. Select whether you want RevenueCat to report sales in purchased currency (original currency or in US dollar)
4. Select whether you want sales reported as gross revenue (before app store commission), or after store commission and/or estimated taxes.

### Events

The Google Analytics portion of the Firebase integration tracks the following events:

| Event Type                        | Default Event Name     | Description                                                                                                                                                                                                                                                                                                                                 | App Store | Play Store | Amazon | Stripe | Promo |
| --------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ---------- | ------ | ------ | ----- |
| Initial Purchase                  | purchase               | A new subscription has been purchased.                                                                                                                                                                                                                                                                                                      | ✅        | ✅         | ✅     | ✅     | ❌    |
| Trial Started                     | rc\_trial\_start         | The start of an auto-renewing subscription product free trial.                                                                                                                                                                                                                                                                              | ✅        | ✅         | ✅     | ✅     | ❌    |
| Renewal (incl. trial conversion)  | purchase               | An existing subscription has been renewed or a lapsed user has resubscribed.                                                                                                                                                                                                                                                                | ✅        | ✅         | ✅     | ✅     | ❌    |
| Cancellation (incl. during trial) | rc\_cancellation        | A subscription or non-renewing purchase has been cancelled. See [cancellation reasons](https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields#cancellation-and-expiration-reasons) for more details.                                                                                                                                                 | ✅        | ✅         | ✅     | ✅     | ✅    |
| Uncancellation                    | rc\_uncancellation      | A non-expired cancelled subscription has been re-enabled.                                                                                                                                                                                                                                                                                   | ✅        | ✅         | ✅     | ❌     | ❌    |
| Non Subscription Purchase         | purchase               | A customer has made a purchase that will not auto-renew.                                                                                                                                                                                                                                                                                    | ✅        | ✅         | ✅     | ✅     | ✅    |
| Subscription Paused               | rc\_subscription\_paused | A subscription has been paused.                                                                                                                                                                                                                                                                                                             | ❌        | ✅         | ❌     | ❌     | ❌    |
| Expiration                        | rc\_expiration          | A subscription has expired and access should be removed. If you have [Platform Server Notifications](https://www.revenuecat.com/docs/platform-resources/server-notifications) configured, this event will occur as soon as we are notified (within seconds to minutes) of the expiration. If you do not have notifications configured, delays may be approximately 1 hour. | ✅        | ✅         | ✅     | ✅     | ✅    |
| Billing Issue                     | rc\_billing\_issue       | There has been a problem trying to charge the subscriber. This does not mean the subscription has expired. Can be safely ignored if listening to CANCELLATION event + cancel\_reason=BILLING\_ERROR.                                                                                                                                          | ✅        | ✅         | ✅     | ✅     | ❌    |
| Product Change                    | rc\_product\_change      | A subscriber has changed the product of their subscription. This does not mean the new subscription is in effect immediately. See [Managing Subscriptions](https://www.revenuecat.com/docs/subscription-guidance/managing-subscriptions) for more details on updates, downgrades, and crossgrades.                                                                         | ✅        | ✅         | ❌     | ✅     | ❌    |
| Transfer                          | rc\_transfer\_event      | A transfer of transactions and entitlements was initiated between one App User ID(s) to another. Please note: Two events will be sent for each transfer, one for the original user and another for the destination user.                                                                                                                    | ✅        | ✅         | ✅     | ✅     | ❌    |

### Testing Google Analytics

#### Make a sandbox purchase with a new user

Simulate a new user installing your app, and go through your app flow to complete the [sandbox purchase](https://www.revenuecat.com/docs/test-and-launch/sandbox).

#### Check Google Analytics Dashboard

Navigate to Google Analytics > Reports > Realtime. Here you will be able to confirm events have been successfully dispatched to Google Analytics. It can take up to a few seconds or minutes for your events to appear.

![Google Analytics dashboard](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/google-analytics-dashboard.png)

### Firebase A/B Testing

While these events will appear in Firebase, Google does not allow events that are submitted via the Google Analytics 4 Measurement Protocol API to be used with Firebase A/B testing at this time. Since the integration uses this API, these events are not yet compatible with Firebase A/B Testing.

:::success
You have completed the Google Analytics setup! You can stop here or continue with the rest of the documentation to learn how to set up the Firebase Extension.
:::

## 4. Send customer information to Firestore

### Prerequisites

This section outlines steps that need to be completed in order to enable the Firebase Extension portion of this integration.

#### Billing

Your Firebase project must be on the Blaze (pay-as-you-go) plan to install an extension.

You will be charged a small amount (typically around $0.01/month) for the Firebase resources required by this extension (even if it is not used). In addition, this extension uses the following Firebase services, which may have associated charges if you exceed the service's free tier for low-volume use ([Learn more about Firebase billing](https://firebase.google.com/pricing)):

- Cloud Firestore
- Cloud Functions

#### Set your Cloud Firestore security rules

Set your security rules so that only authenticated users can access customer information, and that each user can only access their own information.

```js
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Replace 'your_customers_collection' with your actual customers collection name
    match /your_customers_collection/{uid} {
      allow read: if request.auth.uid == uid;
    }

    // Replace 'your_events_collection' with your actual events collection name
    match /your_events_collection/{id} {
      allow read: if request.auth.uid == resource.data.app_user_id;
    }
  }
}
```

### Enable Firebase Extension

You can install this extension either through the [Firebase Console](https://www.revenuecat.com/docs/integrations/third-party-integrations/firebase-integration#install-firebase-extension-through-firebase-console) or [CLI](https://www.revenuecat.com/docs/integrations/third-party-integrations/firebase-integration#install-firebase-extension-through-cli) on your OS.

#### Install Firebase Extension through Firebase Console

Follow [this installation link](https://console.firebase.google.com/project/_/extensions/install?ref=revenuecat/firestore-revenuecat-purchases) to start the installation prompts on Firebase Console.

1. Select 'I acknowledge'

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-1.png)

2. If your account is not set up for billing yet, select 'Upgrade project to continue'

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-2.png)

3. Enable Authentication and Secret Manager by selecting 'Enable', then select 'Next'

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-3.png)

4. Select 'Next'

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-4.png)

5. Configure the extension

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-5.png)

- Select a Cloud Functions location
- (optional) Give a name to the Firestore collection where "events" will be stored
- (optional) Give a name to the Firestore collection where "customers" will be stored
- Enable or disable custom claims set in Firebase Auth with user's active entitlements. If set to “ENABLED”, the extension will consider the `app_user_id` of the user to match the user’s Firebase Authentication UID and set a “Custom Claim” with their current active entitlements
- Enter your RevenueCat Firebase Integration Shared Secret. This can be found in the RevenueCat Firebase Extension settings page. Select 'Generate shared secret' and copy it. Paste the generated shared secret in the installation prompt.

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-6.png)

- (optional) Enable events to write custom event handlers via [Eventarc](https://firebase.google.com/docs/extensions/install-extensions?authuser=0\&hl=en\&platform=console#eventarc)

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-7.png)

##### Available Events:

| Event                   | Description                                                                                                                |
| :---------------------- | :------------------------------------------------------------------------------------------------------------------------- |
| `test`                  | Occurs whenever a test event issued through the RevenueCat dashboard.                                                      |
| `initial_purchase`      | Occurs whenever a new subscription has been purchased or a lapsed user has resubscribed.                                   |
| `non_renewing_purchase` | Occurs whenever a customer has made a purchase that will not auto-renew.                                                   |
| `renewal `              | Occurs whenever an existing subscription has been renewed.                                                                 |
| `product_change`        | Occurs whenever a subscriber has changed the product of their subscription.                                                |
| `cancellation`          | Occurs whenever a subscription or non-renewing purchase has been cancelled. See cancellation reasons for more details.     |
| `uncancellation `       | Occurs whenever an auto-renew status has been re-enabled for a subscription.                                               |
| `billing_issue`         | Occurs whenever there has been a problem trying to charge the subscriber. This does not mean the subscription has expired. |
| `subscriber_alias`      | Deprecated. Occurs whenever a new app\_user\_id has been registered for an existing subscriber.                              |
| `subscription_paused`   | Occurs whenever a subscription has been paused.                                                                            |
| `transfer `             | Occurs whenever a transfer of transactions and entitlements was initiated between one App User ID(s) to another.           |
| `expiration `           | Occurs whenever a subscription has expired and access should be removed.                                                   |

- Select 'Install extension'. This will take about 3-5 minutes to complete

6. Once the extension is installed, navigate to Firebase > Functions in the sidebar. Copy the 'Trigger URL' and paste this into the RevenueCat Firebase Extension settings page.

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-8.png)

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-9.png)

Remember to select 'Save'

:::success
You have successfully installed your instance of Enable In-App Purchases with RevenueCat! Skip to [Testing Firebase Extension](https://www.revenuecat.com/docs/integrations/third-party-integrations/firebase-integration#testing-firebase-extension) section of the docs.
:::

#### Install Firebase Extension through CLI

If you installed the Firebase Extension through the Firebase Console, skip to [Testing Firebase Extension](https://www.revenuecat.com/docs/integrations/third-party-integrations/firebase-integration#testing-firebase-extension) of the docs.

This portion of the installation is done through the command-line interface (CLI). Clone this [Github repo](https://github.com/RevenueCat/firestore-revenuecat-purchases) and open the CLI for your respective operating system.

1. Run `firebase ext:install . --project [project-id]`\
   To find your `project-id`, go to your [Firebase console](https://console.firebase.google.com/u/0/). Select your project and navigate to Project settings to copy the ID and replace `[project-id]` in the command.

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-10.png)

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-11.png)

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-12.png)

2. For the next 2 `Do you wish to continue?` prompts, press `y`

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-13.png)

3. `Please enter a new name for this instance:` Give the extension a name of your choice

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-14.png)

4. `Which option do you want enabled for this parameter (Cloud Functions location)?` Select your desired location

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-15.png)

5. `Enter a value for RevenueCat Webhook Events Firestore collection:` Give a name to the Firestore collection where "events" will be stored. If left blank, RevenueCat will not save events.

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-16.png)

6. `Enter a value for location of the customers collection:` Give a name to the Firestore collection where the customer information will be stored. If left blank, RevenueCat will not save customer information.

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-17.png)

7. `Which option do you want enabled for this parameter (custom claims set in Firebase Auth with the user's active entitlements):` If you want to use the custom claims feature, which allows for automatic checking for Entitlements, select `ENABLED`.

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-18.png)

8. `Enter a value for RevenueCat Firebase Integration Shared Secret:` This can be found in the RevenueCat Firebase Extension settings page. Select 'Generate shared secret' and copy it. Paste the generated shared secret in the installation prompt.

![RevenueCat Firebase Extension page](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-19.png)

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-20.png)

9. Wait about 3 to 5 minutes for the installation

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-21.png)

10. Once the extension is installed, navigate to Firebase > Functions in the sidebar. Copy the 'Trigger URL' and paste this into the RevenueCat Firebase Extension settings page.

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-8.png)

##### Note about the App User ID's in the Customers collection

The document ID's in the Customers collection will always be an App User ID. Specifically, it will be the customer's most recently active alias. This means that the document ID for each customer may switch between [anonymous ID's](https://www.revenuecat.com/docs/customers/user-ids#anonymous-app-user-ids) and [custom ID's](https://www.revenuecat.com/docs/customers/user-ids#logging-in-with-a-custom-app-user-id), if they are both used in your app. If you would like to only use custom ID's, you can [learn more about that here](https://www.revenuecat.com/docs/customers/user-ids#how-to-never-see-anonymous-app-user-ids).

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firebase-console-9.png)

Remember to select 'Save'.

:::success
You have successfully installed your instance of Enable In-App Purchases with RevenueCat!
:::

### Testing Firebase Extension

#### Make a sandbox purchase with a new user

Simulate a new user installing your app, and go through your app flow to complete the [sandbox purchase](https://www.revenuecat.com/docs/test-and-launch/sandbox).

#### Check that the Firebase event delivered successfully

While still on the Customer View, select the purchase event in the [Customer History](https://www.revenuecat.com/docs/dashboard-and-metrics/customer-profile) page and make sure that the Firebase (Firebase function) integration event exists and was delivered successfully.

#### Check Firestore Database Collections

Navigate to your Firebase dashboard > Firestore Database to find events sent for your collections.

![Customers collection](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firestore-customers-collection.png)

![Events collection](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/firestore-events-collection.png)

### Sample Events

Below are sample JSONs that are delivered to Firestore Database for each event type.

**Initial Purchase**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "purchase",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "com.tokens.1000",
                "period_type": "NORMAL",
                "purchased_at": 1658338961415000,
                "environment": "PRODUCTION",
                "presented_offering_id": "",
                "transaction_id": "GPA.1234-5678-9012-34567",
                "affiliation": "PLAY_STORE",
                "original_transaction_id": "GPA.1234-5678-9012-34567",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "currency": "USD",
                "value": 1.99,
                "coupon": "",
                "is_trial_conversion": false,
                "is_renewal": false,
                "items": [
                    {
                        "item_id": "com.tokens.1000",
                        "affiliation": "PLAY_STORE"
                    }
                ]
            }
        }
    ]
}
```

**Trial Started**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_trial_start",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "com.subscription.weekly.2",
                "period_type": "TRIAL",
                "purchased_at": 1660393525000000,
                "environment": "PRODUCTION",
                "presented_offering_id": "",
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_at": 1660652725000000,
                "app_id": "app1234567890"
            }
        }
    ]
}
```

**Trial Cancelled**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_cancellation",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "com.subscription.monthly1",
                "period_type": "TRIAL",
                "purchased_at": 1660161398000000,
                "environment": "PRODUCTION",
                "presented_offering_id": "default",
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_at": 1662839798000000,
                "cancel_reason": "UNSUBSCRIBE",
                "app_id": "app1234567890"
            }
        }
    ]
}
```

**Trial Converted**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "purchase",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "com.subscription.1year",
                "period_type": "NORMAL",
                "purchased_at": 1660422876000000,
                "environment": "PRODUCTION",
                "presented_offering_id": "instantOffer",
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_at": 1691958876000000,
                "app_id": "app1234567890",
                "currency": "USD",
                "value": 59.99,
                "coupon": "",
                "is_trial_conversion": true,
                "is_renewal": false,
                "items": [
                    {
                        "item_id": "com.subscription.1year",
                        "affiliation": "APP_STORE"
                    }
                ]
            }
        }
    ]
}
```

**Renewal**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "purchase",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "monthly_sub_pro",
                "period_type": "NORMAL",
                "purchased_at": 1647907092000000,
                "expiration_at": 1647907392000000,
                "environment": "SANDBOX",
                "presented_offering_id": null,
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "currency": "USD",
                "value": 4.99,
                "coupon": null,
                "is_trial_conversion": false,
                "is_renewal": true,
                "items": [
                    {
                        "item_id": "monthly_sub_pro",
                        "affiliation": "APP_STORE"
                    }
                ]
            }
        }
    ]
}
```

**Cancellation**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_cancellation",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "monthly_sub_pro",
                "period_type": "NORMAL",
                "purchased_at": 1647908709000000,
                "expiration_at": 1647909009000000,
                "environment": "SANDBOX",
                "presented_offering_id": null,
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "cancel_reason": "UNSUBSCRIBE"
            }
        }
    ]
}
```

**Uncancellation**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_uncancellation",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "yearly_sub",
                "period_type": "TRIAL",
                "purchased_at": 1653559391000000,
                "environment": "PRODUCTION",
                "presented_offering_id": null,
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_at": 1653818591000000
            }
        }
    ]
}
```

**Non Subscription Purchase**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "purchase",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "com.tokens.1000",
                "period_type": "NORMAL",
                "purchased_at": 1658338961415000,
                "environment": "PRODUCTION",
                "presented_offering_id": "",
                "transaction_id": "GPA.1234-5678-9012-34567",
                "affiliation": "PLAY_STORE",
                "original_transaction_id": "GPA.1234-5678-9012-34567",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "currency": "USD",
                "value": 1.99,
                "coupon": "",
                "is_trial_conversion": false,
                "is_renewal": false,
                "items": [
                    {
                        "item_id": "com.tokens.1000",
                        "affiliation": "PLAY_STORE"
                    }
                ]
            }
        }
    ]
}
```

**Subscription Paused**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_subscription_paused",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "sub_month_2",
                "period_type": "NORMAL",
                "purchased_at": 1652038237835000,
                "environment": "PRODUCTION",
                "presented_offering_id": "2",
                "transaction_id": "GPA.1234-5678-9012-34567",
                "affiliation": "PLAY_STORE",
                "original_transaction_id": "GPA.1234-5678-9012-34567",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_at": 1654723837835000,
                "auto_resumes_at": 1662665437835000
            }
        }
    ]
}
```

**Expiration**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_expiration",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "monthly_pro",
                "period_type": "NORMAL",
                "purchased_at": 1647908709000000,
                "expiration_at": 1647909009000000,
                "environment": "SANDBOX",
                "presented_offering_id": null,
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_reason": "UNSUBSCRIBE"
            }
        }
    ]
}
```

**Billing Issues**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_billing_issue",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "com.subscription_weekly_trial",
                "period_type": "NORMAL",
                "purchased_at": 1657734228000000,
                "environment": "PRODUCTION",
                "presented_offering_id": "",
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_at": 1658857428000000,
                "grace_period_expires_at": 1658857428000000
            }
        }
    ]
}
```

**Product Change**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_product_change",
           "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "annual_sub",
                "period_type": "NORMAL",
                "purchased_at": 1652866828000000,
                "environment": "SANDBOX",
                "presented_offering_id": null,
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_at": 1652868988000000
            }
        }
    ]
}
```

**Transfer**

```json
{
    "app_instance_id": "1234567ab8901cd234e56f789gh0i123",
    "user_id": "1234567890",
    "events": [
        {
            "name": "rc_transfer",
            "params": {
                "event_id": "12345678-1234-56a7-b8c9-012defg3h4i5",
                "product_id": "com.subscription.weekly.2",
                "period_type": "NORMAL",
                "purchased_at": 1660393525000000,
                "environment": "PRODUCTION",
                "presented_offering_id": "",
                "transaction_id": "123456789012345",
                "affiliation": "APP_STORE",
                "original_transaction_id": "123456789012345",
                "original_app_user_id": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
                "expiration_at": 1660652725000000,
                "app_id": "app1234567890"
                "transferred_from": "$RCAnonymousID:12345678912345678912345678912345",
                "transferred_to": "$RCAnonymousID:87c6049c58069238dce29853916d624c",
            }
        }
    ]
}
```

### Using the Extension

#### Checking Entitlement access

To check access to entitlements, you can either [use the RevenueCat SDK](https://www.revenuecat.com/docs/getting-started/quickstart#10-get-subscription-status) or use Firebase Authentication custom claims. For example, to check whether the current user has access to an entitlement called `premium`, you could use the following Firebase code:

```js
getAuth().currentUser.getIdTokenResult()
  .then((idTokenResult) => {
     // Confirm the user has a premium entitlement.
     if (!!idTokenResult.claims.revenueCatEntitlements.includes("premium")) {
       // Show premium UI.
       showPremiumUI();
     } else {
       // Show regular user UI.
       showFreeUI();
     }
  })
  .catch((error) => {
    console.log(error);
  });
```

#### List a user's active subscriptions

To list a user's active subscriptions, you could use the following Firebase code:

```js
getDoc(doc(db, "${param:REVENUECAT_CUSTOMERS_COLLECTION}", getAuth().currentUser.uid))
  .then((snapshot) => {
    if (snapshot.exists()) {
      snapshot.subscriptions
        .filter(subscription => new Date(subscription.expires_date) >= new Date())
        .forEach(subscription => console.log(JSON.stringify(subscription)));
    }
  });
```

#### React to subscription lifecycle events

Subscription lifecycle events get stored as events in the Firestore collection `${param:REVENUECAT_EVENTS_COLLECTION}`. By listening to changes in this collection, for example, through [Cloud Firestore triggered Firebase Cloud Functions](https://firebase.google.com/docs/functions/firestore-events), you can trigger any custom behavior that you want. An example could be sending push notifications to customers with billing issues to prompt them to update their credit cards. To do that, you would:

- Store a push notification token for each of your app users, e.g., using [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging)
- Create a new Cloud Function triggered whenever a new document is created in the `${param:REVENUECAT_EVENTS_COLLECTION}` collection
- In the Cloud Function, determine if the `type` field of the new document is `"BILLING_ISSUE"`
- If so, look up the app user ID from the `app_user_id` field of the new document
- Look up the push token for that app user ID and send a push notification

## Troubleshooting your Firebase integration

### 403 Permission denied to enable service (eventarcpublishing.googleapis.com)

If you get a 403 error in DeploymentManager when trying to install or uninstall the Firebase extensions, Navigate to [Google Cloud IAM Settings](https://console.cloud.google.com/iam-admin/iam) and follow these steps:

1. Near the top left corner of the page, click **Grant Access**.
2. Once the "Grant Access" popup shows up on the right side of the page, set `<PROJECT_NUMBER>@cloudservices.gserviceaccount.com` as the principal (replacing \<PROJECT\_NUMBER> with your actual project number.)
3. Select the **Editor** role.
4. Click Save.

Now try uninstalling and/or reinstalling the extension.

![](https://www.revenuecat.com/docs_images/integrations/third-party-integrations/firebase/invalid-api-version-error.png)

### InvalidApiVersionError: The version of this extension is not the same.

This is fixed as part of an automatic upgrade process when installing the extension, and generally doesn't indicate there being an issue with your setup. The error should not affect your integration. This is usually not necessary but if you continue seeing this error you may try to uninstall and reinstall the extension.
