# Revenue Cat

[Revenue Cat](https://www.revenuecat.com/) is an in-app subscription platform that lets you analyze and grow your cross-platform app subscriptions.

RudderStack supports Revenue Cat as a destination to which you can seamlessly send your event data.

Find the open source transformer code for this destination in the [GitHub repository](https://github.com/rudderlabs/rudder-transformer/tree/main/src/v0/destinations/revenue_cat).

## Connection compatibility

{{< destination-config >}}

## Get started

Once you have confirmed that the source platform supports sending events to Revenue Cat, follow these steps:

1. From your [RudderStack dashboard](https://app.rudderstack.com/), add a source. Then, from the list of destinations, select **Revenue Cat**.
2. Assign a name to the destination and click **Continue**.

### Connection settings

To successfully configure Revenue Cat as a destination, you will need to configure the following settings:

{{< image src="images/event-stream-destinations/rev-cat-connection-settings.webp" alt="Revenue Cat connection settings" >}}

- **Public API Key**: Enter your Revenue Cat public API key.

{{< info >}}

For more information on getting your Revenue Cat public API key, refer to the [FAQ](#faq) section below.
{{< /info >}}

- **X-Platform**: Select your app platform from the dropdown.

## Identify 

The [`identify`]({{< ref "event-spec/standard-events/identify.md" >}}) method lets you identify a user and associate them to their actions. It also lets you record any traits about them like their name, email, etc.

RudderStack uses the `identify` call to create or update new subscribers in Revenue Cat. It maps `userId` (a required trait in every event) to Revenue Cat's `app_user_id` before sending the data via the [`subscribers`](https://docs.revenuecat.com/reference/subscribers) API.

A sample `identify` call is shown below:

```javascript
rudderanalytics.identify("1hKOmRA4GRlm",{
    email: "alex@example.com",
    phone: "+1-202-555-0146",
})
```

### Traits mapping

RudderStack maps the following `identify` traits to the corresponding Revenue Cat attributes:

| RudderStack trait | Revenue Cat attribute |
| :-------| :--------|
| `userId` (Required) | `app_user_id` |
| `name` | `$displayName` |
| `email` | `$email` |
| `phone` | `$phoneNumber` |
| `apnsTokens` | `$apnsTokens` |
| `fcmTokens` | `$fcmTokens` |
| `context.ip`, `request_ip` | `$ip` |
| `appsflyerId` | `$appsflyerId` |
| `iterableUserId` | `$iterableUserId` |
| `mparticleId` | `$mparticleId` |
| `onesignalId` | `$onesignalId` |
| `airshipChannelId` | `$airshipChannelId` |
| `clevertapId` | `$clevertapId` |

The following `identify` traits are also mapped to the corresponding Revenue Cat attributes: 

{{< warning >}}

Revenue Cat **cannot modify** these attributes so you must send them **only once**.
{{< /warning >}}

| RudderStack trait | Revenue Cat attribute |
| :-------| :--------|
| `idfa`/ `advertisingId` | `$idfa`|
| `idfv`/ `device.id` | `$idfv`|
| `gpsAdId` | `$gpsAdId`|
| `advertisingId` | `$androidId`|
| `campaign.name` | `$campaign`|
| `creative` | `$creative`|
| `keyword` | `$keyword`|
| `mediaSource` | `$mediaSource`| 
| `ad` | `$ad`| 
| `addGroup` | `$adGroup`| 
| `adjustId` | `$adjustId`| 
| `fbAnonId` | `$fbAnonId`|
| `iterableCampaignId` | `$iterableCampaignId`|
| `iterableTemplateId` | `$iterableTemplateId`| 
| `mixpanelDistinctId` | `$mixpanelDistinctId`|
| `amazonAdId` | `$amazonAdId`|

{{< warning >}}

The values for `iterableCampaignId` and `iterableTemplateId` must be valid non-negative, non-decimal integers. Otherwise, RudderStack will reject and skip these fields.
{{< /warning >}}

## Track

The [`track`]({{< ref "event-spec/standard-events/track.md" >}}) method lets you capture user events along with the properties associated with them.

A sample `track` call is shown below:

```javascript
rudderanalytics.track("Order Completed", {
  userId: "1hKOmRA4GRlm",
  currency: "USD",
  fetch_token: "12456",
  products: [{
      product_id: "123454387",
      name: "Game",
      price: 15.99,
      introductory_price: "24",
      is_restore: true,
      presented_offering_identifier: "123",
    }
  ],
});

```

### Event mapping

{{< warning >}}
This destination does not strictly adhere to the [RudderStack Ecommerce Event Spec]({{< ref "event-spec/ecommerce-events-spec/" >}}).
{{< /warning >}}

RudderStack maps the `Order Completed` event to Revenue Cat's `Purchase` event before sending it across via the [`receipts`](https://docs.revenuecat.com/reference/receipts) API. To do so, RudderStack requires the `userId` (mapped to `app_user_id`) and `fetch_token` properties to be present in the event.

### Property mapping

RudderStack maps the following event properties to the corresponding Revenue Cat attributes:

| RudderStack property | Revenue Cat attribute | Comments |
| :-----| :------| :-------|
| `userId` (Required) | `app_user_id` | - |
| `fetch_token` (Required) | `fetch_token` | This must be a Base64 encoded **receipt file** for iOS, **receipt token** for Android, **receipt** for Amazon, and **subscription token** in case of Stripe. |
| `currency` | `currency`  | - |
| `payment_mode` | `payment_mode`  | - |
| `product_id`, `products.product_id` | `product_id`  | This is required for Google and should be the Apple, Google, or Amazon SKU or product identifier. |
| `price` | `price`  | - |
| `introductory_price` | `introductory_price`  | - |
| `is_restore` | `is_restore`  | - |
| `presented_offering_identifier` | `presented_offering_identifier`  | - |

## FAQ 

#### Where can I find the Revenue Cat public API key?

To find the Revenue Cat public API key, follow these steps:

1. Log into your [Revenue Cat dashboard](https://app.revenuecat.com/).
2. From the top navigation bar, go to **Projects** and select your app:

{{< image src="images/event-stream-destinations/rev-cat-project.webp" alt="Revenue Cat project in the dashboard" >}}

3. Under **Project settings**, select **API Keys**. You will find your public API keys under **Public app-specific API keys**:

{{< image src="images/event-stream-destinations/rev-cat-public-api-key.webp" alt="Revenue Cat public API key" >}}



