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.

Identifying Users

How RevenueCat handles user identity

RevenueCat provides a source of truth for a subscriber's status across different platforms. To do this, each subscriber has an App User ID that uniquely identifies them within your application.

Anonymous App User ID

If you don't provide an App User ID when instantiating the Purchases SDK, RevenueCat will create a new random App User ID for you and cache it on the device. In the event that the user deletes and reinstalls the app, a new random App User ID will be generated.

Provided App User ID

Setting your own App User ID will allow you to reference users in the RevenueCat dashboard, via the API, as well as in the webhooks and other integrations.

Using an externally managed App User ID also provides a mechanism by which to restore purchases in a few scenarios:

  • When a user deletes and reinstalls your app - using the same App User ID will ensure they still haves access to subscriptions previously started without requiring a restore.
  • When the user logs in on multiple devices - you can honor a subscription that was purchased on one device across any other platform.

Set App User ID on instantiation

If you have your own App User IDs, you can pass those on instantiation to Purchases.

Purchases.configure(withAPIKey: "my_api_key", appUserID: "my_app_user_id")
[RCPurchases configureWithAPIKey:@"my_api_key" appUserID:@"my_app_user_id"];
Purchases.configure(this, "my_api_key", "my_app_user_id")
Purchases.configure(this, "my_api_key", "my_app_user_id");

Convert Anonymous User to Identifiable User

If you don't have an App User ID on instantiation, you can set it later at any time with the .identify() method. The most common cases are after registration, when a user switches from being an anonymous user (with a random App User ID) to an authenticated user with some ID.

Purchases.shared.identify("my_app_user_id") { (purchaserInfo, error) in
    
    // purchaserInfo updated for my_app_user_id
}
[[RCPurchases sharedPurchases] identify:@"my_app_user_id" completionBlock:^(RCPurchaserInfo *purchaserInfo, NSError *error) {
    
    // purchaserInfo updated for my_app_user_id
}];
Purchases.sharedInstance.identifyWith("my_app_user_id", ::showError) { purchaserInfo ->
  // purchaserInfo updated for my_app_user_id
}
Purchases.getSharedInstance().identify("my_app_user_id", new ReceivePurchaserInfoListener() {
	@Override
	public void onReceived(@android.support.annotation.Nullable PurchaserInfo purchaserInfo, @android.support.annotation.Nullable PurchasesError error) {
		// purchaserInfo updated for my_app_user_id
	}
});

Sharing Subscriptions Across Store Accounts

RevenueCat allows you to choose whether or not users may reuse a subscription from an App or Play Store account that already has that subscription active.

By default, allowSharingAppStoreAccount is treated as True if the App User ID is anonymous, and False if you've provided an App User ID.

Purchases.shared.allowSharingAppStoreAccount = true

Restoring across App User Ids

Restoring purchases is a mechanism by which your user can restore their in-app purchases, reactivating any content that had previously been purchased from the same store account (Apple or Google).

If two different App User IDs try to restore transactions from the same underlying store account (Apple or Google) RevenueCat will automatically merge the two App User IDs and count them as the same user going forward.

Purchases.shared.restoreTransactions { (purchaserInfo, error) in
    //... check purchaserInfo to see if entitlement is now active
}
[[RCPurchases sharedPurchases] restoreTransactionsWithCompletionBlock:^(RCPurchaserInfo *purchaserInfo, NSError *error) {
    //... check purchaserInfo to see if entitlement is now active
}];
Purchases.sharedInstance.restorePurchasesWith(::showError) { purchaserInfo ->
    //... check purchaserInfo to see if entitlement is now active
}
Purchases.getSharedInstance().restorePurchases(new ReceivePurchaserInfoListener() {
	@Override
	public void onReceived(@android.support.annotation.Nullable PurchaserInfo purchaserInfo, @android.support.annotation.Nullable PurchasesError error) {
    //... check purchaserInfo to see if entitlement is now active 	
  }
});
try {
  const restore = await Purchases.restoreTransactions();
  // ... check restored purchaserInfo to see if entitlement is now active
} catch (e) {

}
Purchases.restoreTransactions(
  info => {
    //... check purchaserInfo to see if entitlement is now active
  },
  error => {
    // Error restoring purchases
  }
);
var purchases = GetComponent<Purchases>();
purchases.RestoreTransactions((info, error) =>
{
    //... check purchaserInfo to see if entitlement is now active
});
try {
  PurchaserInfo restoredInfo = await Purchases.restoreTransactions();
  // ... check restored purchaserInfo to see if entitlement is now active
} on PlatformException catch (e) {
  // Error restoring purchases
}

Calling restoreTransactions will always merge accounts, even if allowSharingAppStoreAccount is False.

Logging Out

When a user logs out you should call the reset() method on Purchases to reset the App User ID to a new generated App User ID. This sets you up with a new anonymous user for the logged out state.

Tips for setting App User IDs

App User IDs Should Not Be Guessable

RevenueCat provides subscription status via the public API, having App User IDs that are easily guessed is not good. It is recommended to use a non-guessable psuedo-random ID that isn't made public inside your app.

For App User IDs generated by RevenueCat, we use a UUID.

Don't set emails as App User IDs

For the above reason, and GDPR compliance, we don't recommend using email addresses as App User IDs

Next Steps

Identifying Users


How RevenueCat handles user identity

Suggested Edits are limited on API Reference Pages

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