RevenueCat

Build With RevenueCat

Build a customized mobile subscription business with RevenueCat. We do the heavy lifting of normalizing subscribers from any source and maintain a single source of truth for subscription status, so you can get back to building your app.

RevenueCat is a powerful, secure, reliable, and free to use in-app purchase server with global support. All you need to get started is an API key.

Get Started    API Reference

OneSignal

Integrate RevenueCat subscription status with OneSignal

👍

Integrations are only available on paid plans.

RevenueCat can automatically update user tags in OneSignal with their latest subscription status. This can be helpful in understanding what stage a customer is in to react accordingly. For example, you might want to:

  • Send an onboarding campaign to a user in a free trial
  • Send a push notification to churned users and offer them a discount

With accurate and up-to-date subscription data in OneSignal, you'll be set to turbo charge your campaigns.

For every auto-renewing subscription event in RevenueCat, the following tags get added or updated on the user in OneSignal. By leaving the tag blank in the RevenueCat dashboard, you can choose to not send any value for specific tag(s).

Tag

Description

app_user_id

The RevenueCat App User Id that triggered the event

period_type

The latest period type for the purchase or renewal. Either:

  • TRIAL (for free trials)
  • INTRO (or introductory pricing)
  • NORMAL (standard subscription)

purchased_at

epoch time in seconds of the latest subscription purchase or renewal

expiration_at

epoch time in seconds of the latest subscription expiration date

store

Either APP_STORE , PLAY_STORE, or STRIPE

environment

Either SANDBOX or PRODUCTION

last_event_type

The latest event type from the user. Either:

  • INITIAL_PURCHASE
  • TRIAL_STARTED
  • TRIAL_CONVERTED
  • TRIAL_CANCELLED
  • RENEWAL
  • CANCELLATION

product_id

The latest subscription product identifier that the user has purchased or renewed

entitlement_ids

Comma separated string of RevenueCat Entitlement identifiers that the user unlocked

📘

Auto-renewing subscriptions only

RevenueCat only updates data tags in OneSignal in response to auto-renewing subscription events.

1. Send device data to RevenueCat

The OneSignal integration requires some device-specific data. RevenueCat will only update users in OneSignal if the below data has been added as Subscriber Attributes for the user.

Key

Description

Required

$onesignalId

The OneSignal Player Id for the user.

This preoperty can be set manually, like any other Subscriber Attributes, or through the helper method setOnesignalID().

You can listen for changes to the OneSignal Id through their SDK, and send the value to RevenueCat. If you already have OneSignal set up, you should make sure that you're also sending the OneSignal Id for users that are updating to the latest version of your app.

class AppDelegate: UIResponder, UIApplicationDelegate, OSSubscriptionObserver {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            
        Purchases.configure(withAPIKey: "<revenuecat_api_key>", appUserID: nil)
        
        OneSignal.initWithLaunchOptions(launchOptions, appId: "<onesignal_app_id>")
        OneSignal.add(self as OSSubscriptionObserver)
        
        // If you've already set up OneSignal, then users should already have
        // a OneSignal Id. We can check if it's available and send it to RevenueCat
        if let onesignalId = OneSignal.getUserDevice()?.getUserId() {
            Purchases.shared.setOnesignalID(onesignalId)
        }
        
        return true
    }

    // Add this method to update the $onesignalId in RevenueCat whenever it changes
    // This code should be sufficient to capture all new users if you're setting
    // up OneSignal for the first time.
    func onOSSubscriptionChanged(_ stateChanges: OSSubscriptionStateChanges!) {
        if !stateChanges.from.subscribed && stateChanges.to.subscribed {
            // The user is subscribed
            // Either the user subscribed for the first time
            Purchases.shared.setOnesignalID(stateChanges.to.userId)
        }
    }
}

2. Send RevenueCat events into OneSignal

After you've set up the Purchase SDK to send device data to RevenueCat, you can "turn on" the integration and configure the tag names from the RevenueCat dashboard.

  1. Navigate to your app in the RevenueCat dashboard and choose 'OneSignal' from the integrations menu.
  2. Add your OneSignal App Id and OneSignal API key.
  3. Enter the tag names that RevenueCat should use, or choose the default tag names.

OneSignal configuration screen

3. Testing the OneSignal integration

You can test the OneSignal integration end-to-end before going live. It's recommended that you test the integration is working properly for new users, and any existing users that may update their app to a new version.

Make a sandbox purchase with a new user

Simulate a new user installing your app, and go through your app flow to complete a sandbox purchase.

Check that the required device data is collected

Navigate the the Customer View for the test user that just made a purchase. Make sure that all of the required data from step 1 above is listed as attributes for the user.

Check that the OneSignal event delivered successfully

While still on the Customer View, click into the test purchase event in the Customer History and make sure that the OneSignal integration event exists and was delivered successfully.

👍

You've done it!

You should start seeing subscription data from RevenueCat appear on users in OneSignal

Updated 7 days ago


OneSignal


Integrate RevenueCat subscription status with OneSignal

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.