Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ jobs:
name: Prepare Galaxy Store package
working_directory: react-native-purchases-store-galaxy
command: yarn prepare
- run:
name: Prepare AdMob package
working_directory: react-native-purchases-admob
command: yarn prepare
- run:
name: Tests
command: yarn test --maxWorkers=2
Expand All @@ -127,12 +131,18 @@ jobs:
- run:
name: Galaxy Store API Tests
command: yarn workspace react-native-purchases-store-galaxy apitest
- run:
name: AdMob API Tests
command: yarn workspace react-native-purchases-admob apitest
- run:
name: UI Tests
command: yarn workspace react-native-purchases-ui test
- run:
name: Galaxy Store Tests
command: yarn workspace react-native-purchases-store-galaxy test
- run:
name: AdMob Tests
command: yarn workspace react-native-purchases-admob test
- run:
name: Linter
command: yarn run tslint
Expand Down
6 changes: 5 additions & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ files_with_version_number = {
'./react-native-purchases-store-galaxy/android/build.gradle' => ['versionName \'{x}\''],
'./examples/purchaseTesterTypescript/package.json' => ['"react-native-purchases-store-galaxy": "{x}"'],
'./react-native-purchases-ui/package.json' => ['"version": "{x}"', '"react-native-purchases": "{x}"'],
'./react-native-purchases-admob/package.json' => ['"version": "{x}"', '"react-native-purchases": "{x}"'],
'./ios/RNPurchases.m' => ['return @"{x}"'],
'./android/build.gradle' => ['versionName \'{x}\''],
'./react-native-purchases-ui/android/build.gradle' => ['versionName \'{x}\''],
Expand Down Expand Up @@ -110,7 +111,7 @@ lane :github_release do |options|
)
end

desc "Creates GitHub release and publishes react-native-purchases and react-native-purchases-ui"
desc "Creates GitHub release and publishes react-native-purchases, react-native-purchases-ui, react-native-purchases-store-galaxy and react-native-purchases-admob"
lane :release do |options|
version_number = current_version_number
is_prerelease = prerelease?
Expand All @@ -136,6 +137,9 @@ lane :release do |options|
Dir.chdir(File.expand_path('react-native-purchases-store-galaxy', get_root_folder)) do
sh(args)
end
Dir.chdir(File.expand_path('react-native-purchases-admob', get_root_folder)) do
sh(args)
end
github_release(version: version_number)
end

Expand Down
2 changes: 1 addition & 1 deletion fastlane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Make github release
[bundle exec] fastlane release
```

Creates GitHub release and publishes react-native-purchases and react-native-purchases-ui
Creates GitHub release and publishes react-native-purchases, react-native-purchases-ui, react-native-purchases-store-galaxy and react-native-purchases-admob

### build_example

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"!**/*.iml",
"!**/.DS_Store",
"!**/.gitignore",
"!react-native-purchases-admob",
"!react-native-purchases-store-galaxy",
"!react-native-purchases-ui",
"!scripts/docs/index.html",
Expand All @@ -47,6 +48,7 @@
},
"workspaces": [
"examples/purchaseTesterTypescript",
"react-native-purchases-admob",
"react-native-purchases-store-galaxy",
"react-native-purchases-ui",
"e2e-tests/MaestroTestApp"
Expand Down Expand Up @@ -108,6 +110,7 @@
"preset": "@react-native/jest-preset",
"modulePathIgnorePatterns": [
"<rootDir>/examples/purchaseTesterTypescript/",
"<rootDir>/react-native-purchases-admob/",
"<rootDir>/react-native-purchases-store-galaxy/",
"<rootDir>/react-native-purchases-ui/",
"<rootDir>/dir/"
Expand Down
80 changes: 80 additions & 0 deletions react-native-purchases-admob/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# OSX
#
.DS_Store

# XDE
.expo/

# VSCode
.vscode/
jsconfig.json

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IJ
#
.classpath
.cxx
.gradle
.idea
.project
.settings
local.properties
android.iml

# Cocoapods
#
example/ios/Pods

# Ruby
example/vendor/

# node.js
#
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Expo
.expo/

# Turborepo
.turbo/

# generated by bob
lib/

dist/
3 changes: 3 additions & 0 deletions react-native-purchases-admob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 10.14.0
### ✨ New Features
* Initial release of `react-native-purchases-admob`: automatic ad tracking and rewarded-ad reward verification for `react-native-google-mobile-ads` 17+.
20 changes: 20 additions & 0 deletions react-native-purchases-admob/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2023 RevenueCat
Comment thread
peterporfy marked this conversation as resolved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
92 changes: 92 additions & 0 deletions react-native-purchases-admob/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<p align="center">
<img src="https://uploads-ssl.webflow.com/5e2613cf294dc30503dcefb7/5e752025f8c3a31d56a51408_logo_red%20(1).svg" width="350" alt="RevenueCat"/>
<br>

[![npm](https://img.shields.io/npm/v/react-native-purchases-admob.svg)](https://www.npmjs.com/package/react-native-purchases-admob)

## react-native-purchases-admob

_react-native-purchases-admob_ connects [react-native-google-mobile-ads](https://github.com/invertase/react-native-google-mobile-ads) to [RevenueCat](https://www.revenuecat.com/)'s ad tracking and reward verification. Create your ads through the adapter and it reports loaded, failed-to-load, displayed, opened, revenue and earned-reward events for you; rewarded ads can additionally have their rewards verified server-side. See the [AdMob integration docs](https://www.revenuecat.com/docs/ad-monetization/admob) for the full picture.

## Installation

```sh
yarn add react-native-purchases react-native-google-mobile-ads react-native-purchases-admob
```

Requires `react-native-google-mobile-ads` 17 or newer (the first version that exposes `responseInfo` and `valueMicros` on every ad format). Configure `Purchases` and initialize `mobileAds()` as you normally would; the adapter only tracks while `Purchases` is configured.

## Tracking full-screen ads

Replace `InterstitialAd.createForAdRequest(...)` with the matching `RevenueCatAdMob.create...` call. The returned object is the same `InterstitialAd`, so `load()`, listeners and `destroy()` work as before; `placement` is a free-form label for where the ad is shown.

```ts
import { RevenueCatAdMob } from "react-native-purchases-admob";

const interstitial = RevenueCatAdMob.createInterstitialAd(adUnitId, {
placement: "level_complete",
requestOptions: { keywords: ["game"] },
});
interstitial.addAdEventListener(AdEventType.LOADED, () => setReady(true));
interstitial.load();

// Later. The placement given here overrides the load-time one for this impression.
await RevenueCatAdMob.showAndTrack(interstitial, {
placement: "level_complete_retry",
});
```

`createAppOpenAd` works the same way. For an ad you created yourself, call `RevenueCatAdMob.trackAd(ad, { placement })` before `load()`.

## Banner and native ads

```tsx
import { useTrackingBannerAdProps } from "react-native-purchases-admob";

function HomeBanner() {
const bannerProps = useTrackingBannerAdProps({
unitId,
size: BannerAdSize.BANNER,
placement: "home_bottom",
onPaid: (paid) => console.log(paid.value),
});
return <BannerAd {...bannerProps} />;
}

const nativeAd = await NativeAd.createForAdRequest(adUnitId);
RevenueCatAdMob.trackNativeAd(nativeAd, { placement: "feed" });
```

Banners are a component, not an ad object, and their events arrive through props that React re-evaluates on every render, which is why they get a hook while every other format does not. Your own banner callbacks (`onAdLoaded`, `onPaid`, ...) are forwarded. Class components can use `RevenueCatAdMob.trackingBannerAdProps(...)` instead; it returns the same props but starts a new tracking state on every call, so call it once per banner instance (for example in the constructor), not inside `render`.

## Reward verification

`react-native-google-mobile-ads` only accepts server-side verification options when the ad request is created, before AdMob's response id exists. The adapter therefore generates the impression id itself when you opt in, attaches the RevenueCat token to the request, and uses that id for every tracking event of the ad.

```ts
const rewarded = await RevenueCatAdMob.createRewardedAd(adUnitId, {
placement: "extra_life",
enableRewardVerification: true,
});
rewarded.load();

await RevenueCatAdMob.showWithRewardVerification(rewarded, {
onRewardVerificationStarted: () => showSpinner(),
onRewardVerificationCompleted: (result) => {
if (result.failed) return showError();
grant(result.reward);
},
});
```

Verification tokens are single-use, so create a new ad for every verified show rather than calling `load()` again on the same instance; after it has loaded, a second `load()` on a verified instance logs a warning and does nothing (a retry after a load error still works). `onRewardVerificationCompleted` is called at most once per show, after the user earns the reward; it is not called when the ad is dismissed or fails before a reward. The ad unit's server-side verification URL must point at RevenueCat and a reward must be configured for it in the RevenueCat dashboard; see the [rewards docs](https://www.revenuecat.com/docs/ad-monetization/rewards).

## Not covered

The `useInterstitialAd` / `useRewardedAd` hooks create their ads internally and cannot be routed through the adapter; use the class API above. Ad pools and multi-format requests are not tracked.

## Requirements

- iOS 15.0+ (ad tracking is unavailable below that; calls are ignored with a warning)
- `react-native-google-mobile-ads` 17.x (17.0.0 needs React Native 0.76+, 17.1.0+ needs 0.86+) and the New Architecture
- `react-native-purchases` 10.14.0
Loading