Remove Ads with a React Native Subscription: Expo, AdMob, and Entitlements
If your React Native app earns from ads, some users will happily pay to make them go away. This walkthrough builds exactly that switch: a monthly subscription that hides banner ads once it is active. You will configure the product in both app stores, render banners with Google Mobile Ads, and read a subscription entitlement to decide whether the ad slot should exist at all. One Expo codebase covers iOS and Android, and the example keeps a single monthly product so the purchase logic stays small.
What you will build
The finished sample is a small reading app. Users without an active subscription see banner ads placed between content blocks. A purchase button starts the monthly subscription flow. After a successful purchase, the app checks customer information, finds the ad-free entitlement, and stops rendering the banner. The same entitlement check also runs when the app starts, so returning subscribers do not see ads again.
The project uses two native modules: react-native-google-mobile-ads for ads and react-native-purchases for in-app purchases. Because Expo Go does not support the native modules required by react-native-purchases, the project needs a development build. The example template is configured with Expo, react-native-google-mobile-ads, and expo-dev-client; install dependencies with npm install and start the development server with npx expo start. Testing purchases is best on a real device.
Store and product setup
Before writing purchase code, create the subscription in both stores. The source example configures one monthly recurring subscription priced at 5 dollars; confirm your own price and terms before publishing. Connect the App Store and Play Store to your subscription platform, then create products, offerings, and entitlements so that the project has:
- One entitlement for the ad-free level, identified as
ad_free_entitlement. - Two separate products, one for the App Store and one for the Play Store, for example with the identifier
ad_free_monthly. - Matching subscriptions in the Play Store console and App Store Connect with the same identifiers.
Group the products under the entitlement you created. The entitlement is the stable gate in the app; the store product identifiers belong to the purchase layer. Keeping that separation makes it easier to add or rename products later without changing the UI condition that hides ads.
Add subscriptions and gate the ads
Install the subscription packages using the exact command in protected module code0007.
Initialize the subscription SDK when the app mounts. Set the log level to debug during development, then call Purchases.configure with the iOS API key on iOS and the Android API key on Android. Replace the placeholder keys with the values from your project settings, and review any SDK error logs before continuing.
The ad-free check belongs in a custom hook, useIsAdFree. It calls Purchases.getCustomerInfo(), reads customerInfo.entitlements.active["ad_free_entitlement"], and returns both the boolean result and a loading flag. If the entitlement lookup throws, the hook logs the error and treats the user as not ad-free. The screen uses the loading flag to show a loader while the check runs, then renders the banner only when the entitlement is absent.
Purchasing is handled by a second hook, usePurchaseSubscription. The sample uses a single product and a simple error path; a production app with several products should distinguish cancellation, network failure, and store errors. After the purchase completes, the entitlement check should run again so the UI reflects the new state. The sample's test flow is: press the purchase button, complete the subscription, see the loader, and watch the ads disappear.
Telling ad failures apart from entitlement failures
When the ad-free flow does not behave as expected, the symptom usually points to one of two layers. Use this checklist to narrow it down before changing code.
| Symptom | Likely layer | What to inspect |
|---|---|---|
| App crashes at launch after adding ads | AdMob configuration | The iosAppId and androidAppId values in the Google Mobile Ads plugin; an invalid key crashes the app. |
| Banner area is blank after returning from the background | Banner lifecycle | Whether useForeground is requesting a new ad on iOS. |
| Banner still appears after purchase | Entitlement gate | Whether the active entitlement key is exactly ad_free_entitlement and whether the customer info was refreshed after purchase. |
| Loader never resolves | Entitlement fetch | SDK initialization, API keys, and error logs from getCustomerInfo. |
| Purchase button does nothing | Purchase flow | Whether usePurchaseSubscription is wired to the button and whether the product is attached to the entitlement. |
A useful rule: ad problems usually affect what is rendered inside the banner slot, while entitlement problems affect whether the banner slot should exist at all. Checking the customer object first separates the two.
What is still missing before launch
The sample demonstrates the core loop, but store review usually expects more. Restoring purchases is the most important gap: a subscriber who reinstalls the app must be able to recover access without paying again. Paywalls, subscription testing, and a launch checklist are also worth completing before submission. The source example includes a finished branch with the full code from this walkthrough; an owned sample repository URL must be supplied before linking it.
Frequently asked questions
Why can't I test this in Expo Go?
react-native-purchases relies on native modules, and Expo Go does not include them. Create a development build with expo-dev-client and install it on a device or simulator before testing purchases.
Should the app check the product ID or the entitlement?
Check the entitlement. The sample uses ad_free_entitlement as the condition for hiding ads, while the store products use identifiers such as ad_free_monthly. The entitlement stays stable even if product identifiers change.
Which ad unit ID should I use during development?
Use TestIds.ADAPTIVE_BANNER in development and a real AdMob ad unit ID in production. The sample selects between them with __DEV__.
Do I need restore purchases before submitting?
Yes. The sample notes that restoring purchases is one of the features still needed for store acceptance. Without it, a returning subscriber cannot recover access after reinstalling.