Engineering

App Feature Flags Using Entitlements

Entitlements aren’t limited to in-app purchases

Using Entitlements for Feature Flags
Cody Kerns
Cody KernsDecember 14, 2021

RevenueCat Entitlements are a simple way to grant access to features in your app. An entitlement is just what it sounds like — it’s what a user is entitled to, based on the purchases they’ve made.

Entitlements are considered active for the duration of the user’s subscription. Once the subscription is cancelled or expired, the entitlement is no longer considered active.

Typically, you’ll give an entitlement an identifier (like ‘premium’) and connect it to a product from the App Store or Google Play. Once a user purchases the subscription product, RevenueCat grants access to the entitlement, and the user can access premium features. A one-time purchase will grant access to an entitlement forever, unless the purchase gets refunded.

Entitlements aren’t limited to in-app purchases, though — they’re a remotely configurable access system for any feature of your app. For example, if you have beta testers that should have access to a different set of features than your regular users, you could use an entitlement to grant access to those users, without creating any new products in an app store. Or you could give users access to an individual subscription feature without them having to purchase a full subscription. 

In this post, I’ll show you how to create a beta entitlement and give users access to it. Let’s dive in!

Creating feature flag entitlements

Let’s create an empty entitlement to use for granting access to beta features in your app. Head over to the RevenueCat dashboard and go to your app’s entitlement settings. Create a new entitlement with the identifier “beta” and enter a description of what this entitlement represents.

Ta-da! You’ve created a new entitlement. But you’ll notice there’s a warning icon indicating that something isn’t set up right. This icon means that no products are attached to this entitlement, so no in-app purchases will unlock it. Since we’re going to be granting this entitlement manually, we can safely ignore this warning.

Checking for access from the SDK

To the SDK, this entitlement is no different from any other entitlement. The user’s `CustomerInfo` object will include whether the entitlement is active, regardless of whether a purchase occurred or the entitlement was granted manually. Let’s check to see if this beta entitlement is active:

1Purchases.shared.getPurchaserInfo { info, error in	
2// info.entitlements[“beta”]?.isActive == true
3}

Now we’re ready to start giving beta users access to new features. 

Granting entitlement access to users

We’ve already established that a user cannot make an in-app purchase to unlock our new beta entitlement. And that’s okay, because for now we’re going to be manually granting access to a limited number of users.

Finding users

There are a few different ways of determining who should be included in a beta. For this walkthrough, let’s use a Customer List. 

Let’s filter by users who have been paid subscribers for a long time (since before 2020) and currently have an active subscription. These are the long-time supporters of the app — let’s thank them for their support by giving them access to the beta. 

(You can filter by whatever attributes make the most sense to you.)

Voilà! We found 33 users who have been continuous supporters for a long time. You can click their user IDs to view their customer profiles, or you can export the list for processing later.

Granting access via the Dashboard

If you’re granting beta access to a small set of users, the easiest way to do it is from the Dashboard. If you don’t already have a set of user IDs, you can find them by visiting the Customers tab.

From the customer’s history page, you can grant the user access to the beta with a promotional entitlement. Select the beta entitlement and the length of time you’d like the user to have access to the beta features.

Click Grant. Now the user has access to the entitlement without having to make any purchases!

Granting access via the REST API

If you want to scale beta access to a lot of users, the RevenueCat REST API includes methods to grant and revoke promotional entitlements.

To grant a user a promotional entitlement using the API, send a POST request to our API with the user ID, entitlement identifier, and duration:

1curl --request POST \     
2--url https://api.revenuecat.com/v1/subscribers/app_user_id/entitlements/entitlement_identifier/promotional \     
3--header 'Accept: application/json' \     
4--header 'Authorization: Bearer REVENUECAT_API_KEY' \     
5--header 'Content-Type: application/json'     
6--data '
7{     
8"duration": "lifetime"
9}
10'

Since this request modifies the user’s access to entitlements, you’ll need to authenticate with a Secret API Key.

Summary

Now you’re granting beta access to a handful of your most supportive customers! But the power of entitlements doesn’t stop there. By using the entitlements system as a remote configuration tool, you can create individual entitlements for each of your features to provide even more flexibility and customer support opportunities.

Learn more about entitlements:

Subscribe to our monthly newsletter

Related posts

Google Play class action developer lawsuit
Engineering

Google Play Billing Library 5.0, an overview

Everything you need to know about Google Play Billing Library 5

Rik Haandrikman

Rik Haandrikman

November 25, 2022

Engineering

How RevenueCat’s SDK team uses Release Trains

How we automate the releases of our SDKs

Cesar de la Vega

Cesar de la Vega

October 31, 2022

Stripe for In-App Purchases
Engineering

Can You Use Stripe for In-App Purchases?

Learn about when you can use Stripe and opportunities to save money on fees.

Corey Rabazinski

Corey Rabazinski

October 31, 2022

Want to see how RevenueCat can help?

RevenueCat enables us to have one single source of truth for subscriptions and revenue data.

Olivier Lemarie, PhotoRoomOlivier Lemarie, PhotoRoom
Read case study