Segment

Integrate in-app subscription events from RevenueCat with Segment

👍

The Segment integration is available on the Pro plan.

RevenueCat can automatically send subscription events into Segment. From there, you pass these events on to any of the hundreds of other integrations on their platform. This is useful for tracking all events and revenue that occur for your app even if it's not active for a period of time.

Events

The Segment integration tracks the following events:

EventDescription
Initial PurchaseThe first purchase of an auto-renewing subscription product that does not contain a free trial.
Trial StartedThe start of an auto-renewing subscription product free trial.
Trial ConvertedWhen an auto-renewing subscription product converts from a free trial to normal paid period.
Trial CancelledWhen a user turns off renewals for an auto-renewing subscription product during a free trial period.
RenewalWhen an auto-renewing subscription product renews OR a user repurchases the auto-renewing subscription product after a lapse in their subscription.
CancellationWhen a user turns off renewals for an auto-renewing subscription product during the normal paid period.
UncancellationWhen a user re-enables the auto-renew status for a subscription.
Non Subscription PurchaseThe purchase of any product that's not an auto-renewing subscription.
Subscription pausedA subscription has been paused.
ExpirationA subscription has expired and access should be removed.
Billing IssuesThere has been a problem trying to charge the subscriber.

This does not mean the subscription has expired (in the case of a grace period enabled).

For events that have revenue, such as trial conversions and renewals, RevenueCat will automatically record this amount along with the event in Segment.

Setup

1. Set Segment User Identity

If you're using the Segment SDK, you can set the User ID to match the RevenueCat App User Id. This way, events sent from the Segment SDK and events sent from RevenueCat can be synced to the same user.

Use the .identify() method on the Segment SDK to set the same App User Id that is set in RevenueCat.

// Configure Purchases SDK
Purchases.configure(withAPIKey: "public_sdk_key", appUserID: "my_app_user_id")

// Set App User Id in Segment
SEGAnalytics.sharedAnalytics().identify("my_app_user_id")
// Configure Purchases SDK
[RCPurchases configureWithAPIKey:@"public_sdk_key" appUserID:@"my_app_user_id"];

// Set App User Id in Segment
[[SEGAnalytics sharedAnalytics] identify:@"my_app_user_id"];
// Configure Purchases SDK
Purchases.configure(this, "public_sdk_key", "my_app_user_id");

// Set App User Id in Segment
Analytics.with(context).identify("my_app_user_id", null, null);

2. Generate a Segment Write Key

In Segment, add a HTTP API as a source and copy the Write Key.

12821282

3. Send RevenueCat events to Segment

After you've set up the Purchases SDK and Segment SDK to have the same user identity, you can "turn on" the integration and configure the event names from the RevenueCat dashboard.

  1. Navigate to your project in the RevenueCat dashboard and find the Integrations card in the left menu. Select + New
332332
  1. Choose Segment from the integrations menu
  2. Add your Segment Write Key from step 2
  3. Enter the event names that RevenueCat will send or choose the default event names
  4. Select whether you want RevenueCat to report proceeds (after app store cut) or revenue (gross sales)
  5. Select whether you want RevenueCat to send sandbox events into Segment or not. You can check the environment key in the context property of the event to determine if it was triggered in a sandbox or production environment.
566566

Segment configuration screen

Sample Event

Below is sample JSON that is delivered to Segment for a renewal event.

{
  "identify": {
    "context": {
      "environment": "production",
      "library": {
        "name": "RevenueCat Segment events",
        "version": "1.0"
      }
    },
    "timestamp": "2021-03-20T00:00:02",
    "traits": {
      "aliases": [
        "$RCAnonymousID:0123456789abcdefghij0123456789ab",
        "myCustomAppUserId"
      ],
      "last_seen_app_user_id": "myCustomAppUserId"
    },
    "userId": "$RCAnonymousID:0123456789abcdefghij0123456789ab"
  },
  "track_event": {
    "context": {
      "environment": "production",
      "library": {
        "name": "RevenueCat Segment events",
        "version": "1.0"
      }
    },
    "event": "renewal_event",
    "properties": {
      "app_user_id": "myCustomAppUserId",
      "currency": "USD",
      "entitlements": [
        "your_entitlement_id"
      ],
      "entitlement": "your_entitlement_id",
      "expires_at": 1647734402,
      "original_app_user_id": "$RCAnonymousID:0123456789abcdefghij0123456789ab",
      "product_id": "your_product_id",
      "revenue": 9.99,
      "store": "APP_STORE",
      "purchased_at": 1616198402,
      "subscriber_attributes": {
        "$ip": "000.00.00.000",
        "$idfa": "12345678-1234-1234-1234-123456789abc",
        "$idfv": "12345678-1234-1234-1234-123456789abc",
        "$email": "[email protected]",
        "$fbAnonId": "12345678-1234-1234-1234-123456789abc",
        "$apnsTokens": "fY1kOQ0bMl8:APA91bG_rM-ub0xg:DNjP553d8O8gTYs9iNWsYxZMLyzv46IhB--2qz810LRUhCIXTJE4_Umx-irs-FD6ET_qMCXyNeny7B6xn2-X0v69Be014Qa4BHv2XSTwrmF5PZ2L_LPxw4sL2_s1",
        "$appsflyerId": "0123456789012-0123456",
        "favorite_food": "pizza"
      },
      "period_type": "NORMAL",
      "environment": "PRODUCTION",
      "presented_offering_id": "default",
      "transaction_id": "012345678912345",
      "original_transaction_id": "987654321098765",
      "aliases": [
        "$RCAnonymousID:0123456789abcdefghij0123456789ab",
        "myCustomAppUserId"
      ]
    },
    "timestamp": "2021-03-20T00:00:02",
    "userId": "$RCAnonymousID:0123456789abcdefghij0123456789ab"
    }
}