@rediads/react-native-ads-gam 0.1.0-beta.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -1
- package/README.md +58 -10
- package/android/build.gradle +35 -5
- package/android/consumer-rules.pro +7 -0
- package/build/RediadsGAM.js +1 -1
- package/build/RediadsGAMBiddingOnlyFullScreenAd.js +10 -2
- package/build/RediadsGAMFullScreenAd.js +10 -2
- package/ios/RediadsAdsGAM.podspec +6 -4
- package/ios/RediadsGAMModule.swift +15 -1
- package/ios/RediadsGAMRenderedModule.swift +14 -1
- package/package.json +4 -3
- package/plugin/withRediadsGAM.js +26 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.1.0
|
|
3
|
+
## 0.1.0 (24 Nov 2026)
|
|
4
|
+
|
|
5
|
+
The first release without "beta".
|
|
6
|
+
|
|
7
|
+
- Native SDK: iOS pod `RediadsGAM` 0.1.4, Android `com.rediads:rediads-gam:0.1.1`.
|
|
8
|
+
- Android SDK 0.1.1, not 0.1.0: 0.1.0's GAM classes crash with `NoSuchMethodError` (bidding only) or
|
|
9
|
+
hang (SDK-rendered) on Google Mobile Ads 24.1.0 or later, this package's default 25.5.0 included;
|
|
10
|
+
Google moved `addCustomTargeting` in 24.1.0. 0.1.1 works on 23.0.0 to 25.5.0. It also keeps the
|
|
11
|
+
shown banner when a refresh fails to render (see `@rediads/react-native-ads`).
|
|
12
|
+
- Google's Mobile Ads SDK is the app's own and is never raised: iOS 12.0.0 or later (was 13.0.0), Android
|
|
13
|
+
23.0.0 or later. The Android SDK no longer brings play-services-ads; this package adds 25.5.0 as a
|
|
14
|
+
Gradle "prefer" only when nothing else in the app asks for one, so the app's version (or
|
|
15
|
+
react-native-google-mobile-ads's) always wins. The config plugin's new `androidGoogleMobileAdsVersion`
|
|
16
|
+
option prefers another version, or `"none"` adds nothing. README: "Google's Mobile Ads SDK".
|
|
17
|
+
- GAM interstitials and rewarded ads (SDK-rendered and bidding only): a listener that throws no longer
|
|
18
|
+
stops the other listeners or reaches the native event callback, where it closed a release build; the
|
|
19
|
+
error goes to `console.error`.
|
|
20
|
+
- iOS: loading an ad again under its ID (the same object's `load()`) lets go of the old ad first, as
|
|
21
|
+
Android does, so none of the old ad's events (a late `loaded`, the `dismissed` of one on screen) reach
|
|
22
|
+
JavaScript as the new ad's.
|
|
23
|
+
- Below Android 10 the Android SDK (since 0.1.0) answers every call with "Android 10 or newer is needed ..."
|
|
24
|
+
(`UNSUPPORTED_OS`) and stays off; the bridge passes the error on unchanged (README).
|
|
25
|
+
- Android release builds no longer crash at start under R8: `android/consumer-rules.pro` keeps the
|
|
26
|
+
constructors of Room databases (WorkManager's `WorkDatabase_Impl`, which Google's Mobile Ads SDK
|
|
27
|
+
brings). The Rediads Android SDK 0.1.0 has this rule too (0.1.0-beta1 didn't).
|
|
28
|
+
- Works next to react-native-google-mobile-ads, as the AdMob package: shared app IDs (required with
|
|
29
|
+
that library), `tools:replace` on the Android app ID, a clear Android build error with its Next-Gen
|
|
30
|
+
SDK. README: "With react-native-google-mobile-ads".
|
|
31
|
+
|
|
32
|
+
## 0.1.0-beta.1 (17 Nov 2026)
|
|
4
33
|
|
|
5
34
|
- SDK-rendered GAM: `RediadsGAMBanner` (320x50, 300x250, refreshes itself), `RediadsGAMInterstitial`
|
|
6
35
|
and `RediadsGAMRewarded` over the SDK's classes of the same names; events say who drew the ad
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ and decides. Two modes, per slot:
|
|
|
11
11
|
| Rediads impression and viewability | Yes | Not yet |
|
|
12
12
|
| GAM creative for Rediads line items | Prebid's "app event" creative, line items targeting `rediads_render` = `sdk` | Universal Creative (SafeFrame off), line items excluding `rediads_render` = `sdk` |
|
|
13
13
|
| Banner refresh | Automatic (`refreshInterval`) | Load again (a new `key`) |
|
|
14
|
-
|
|
|
14
|
+
| Loads GAM through react-native-google-mobile-ads | No (the SDK loads GAM; both can be in one app) | Yes, through `fetchTargeting` |
|
|
15
15
|
|
|
16
16
|
Every request from the SDK-rendered classes carries `rediads_render=sdk`.
|
|
17
17
|
|
|
@@ -30,20 +30,25 @@ if ((await ad.load()) === null) await ad.show();
|
|
|
30
30
|
const { targeting } = await RediadsGAM.fetchTargeting({ type: 'banner', placement: 'home_mrec' });
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
This is a **beta** (`0.1.0-beta.1`): install it with the `beta` tag.
|
|
34
|
-
|
|
35
33
|
## Requirements
|
|
36
34
|
|
|
37
35
|
- `@rediads/react-native-ads` of the same version (it starts the Rediads SDK).
|
|
38
36
|
- Expo SDK 58 or later (React Native 0.88): an Expo app, or a bare React Native app with Expo modules.
|
|
39
|
-
- iOS 16.4 or later,
|
|
37
|
+
- iOS 16.4 or later, and a development build (not Expo Go).
|
|
38
|
+
- Supported: Android 10+ (builds with minSdk 24; ads stay off below Android 10). Below Android 10,
|
|
39
|
+
`start`, every load and every banner answer with the error "Android 10 or newer is needed (this device
|
|
40
|
+
runs API N); the Rediads SDK stays off." (the Android SDK's `UNSUPPORTED_OS`), without a request; in
|
|
41
|
+
the AdMob and GAM packages it comes as the `bid` event's error and Google's ad still loads. Nothing to
|
|
42
|
+
fix in the app.
|
|
43
|
+
- Google's Mobile Ads SDK: the app's own version is used and never raised. iOS 12.0.0 or later, Android
|
|
44
|
+
(play-services-ads) 23.0.0 or later. See [Google's Mobile Ads SDK](#googles-mobile-ads-sdk).
|
|
40
45
|
|
|
41
46
|
## Install
|
|
42
47
|
|
|
43
48
|
### Expo apps
|
|
44
49
|
|
|
45
50
|
```sh
|
|
46
|
-
npm install @rediads/react-native-ads
|
|
51
|
+
npm install @rediads/react-native-ads @rediads/react-native-ads-gam
|
|
47
52
|
```
|
|
48
53
|
|
|
49
54
|
In `app.json`:
|
|
@@ -66,13 +71,14 @@ Then a development build: `npx expo prebuild --clean`, then `npx expo run:ios` a
|
|
|
66
71
|
which Google's SDK accepts instead of an ID. If another plugin sets the app ID
|
|
67
72
|
(react-native-google-mobile-ads, `@rediads/react-native-ads-admob`), give the same ID here.
|
|
68
73
|
- Like `@rediads/react-native-ads`, the plugin adds Rediads' pod list to the Podfile sources (once).
|
|
69
|
-
Android
|
|
74
|
+
On Android the SDK comes from Maven Central; for Google's SDK see
|
|
75
|
+
[Google's Mobile Ads SDK](#googles-mobile-ads-sdk).
|
|
70
76
|
|
|
71
77
|
### Bare React Native apps
|
|
72
78
|
|
|
73
79
|
1. Set up `@rediads/react-native-ads` first (Expo modules, the two Podfile `source` lines; see its
|
|
74
80
|
README).
|
|
75
|
-
2. `npm install @rediads/react-native-ads-gam
|
|
81
|
+
2. `npm install @rediads/react-native-ads-gam`
|
|
76
82
|
3. **iOS:** in `Info.plist`, `GADApplicationIdentifier` = your app ID, or `GADIsAdManagerApp` = YES;
|
|
77
83
|
and Google's SKAdNetwork ID `cstr6suwn9.skadnetwork` in `SKAdNetworkItems`. Then
|
|
78
84
|
`cd ios && pod install`.
|
|
@@ -83,9 +89,51 @@ Then a development build: `npx expo prebuild --clean`, then `npx expo run:ios` a
|
|
|
83
89
|
### What gets installed
|
|
84
90
|
|
|
85
91
|
The JavaScript API (compiled, with types), the native bridge as Swift and Kotlin source, and the
|
|
86
|
-
Rediads SDK's GAM part as binaries: on iOS the pod `RediadsGAM` 0.1.
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
Rediads SDK's GAM part as binaries: on iOS the pod `RediadsGAM` 0.1.4 (with `RediadsGAMEventHandlers`),
|
|
93
|
+
on Android `com.rediads:rediads-gam:0.1.1` (with its event handlers). Google's Mobile Ads SDK is the
|
|
94
|
+
app's own: see below.
|
|
95
|
+
|
|
96
|
+
### Google's Mobile Ads SDK
|
|
97
|
+
|
|
98
|
+
A publisher keeps its own version of Google's Mobile Ads SDK; the Rediads packages never raise it.
|
|
99
|
+
|
|
100
|
+
- **iOS:** the pods ask for `Google-Mobile-Ads-SDK` 12.0.0 or later. CocoaPods uses the version the
|
|
101
|
+
app (or react-native-google-mobile-ads) pins; with nothing pinned it takes the newest.
|
|
102
|
+
- **Android:** the Rediads SDK (0.1.1) doesn't bring play-services-ads; it works with 23.0.0 or later.
|
|
103
|
+
The version the app (or react-native-google-mobile-ads) asks for is used, even an older one. Only when
|
|
104
|
+
nothing in the app asks for play-services-ads does this package add one: 25.5.0, as a Gradle "prefer"
|
|
105
|
+
(the weakest kind, so any other declaration wins). To prefer another version, or to add nothing
|
|
106
|
+
(`"none"`, when the app brings play-services-ads some other way), set the config plugin's
|
|
107
|
+
`androidGoogleMobileAdsVersion` option (`"25.5.0"`, `"24.6.0"`, `"none"`), or in a bare app the
|
|
108
|
+
Gradle property `rediadsGoogleMobileAdsVersion` in `android/gradle.properties`.
|
|
109
|
+
- Below 23.0.0 on Android the Rediads SDK logs an error and gets no Rediads bids; Google's ads still load.
|
|
110
|
+
|
|
111
|
+
### With react-native-google-mobile-ads
|
|
112
|
+
|
|
113
|
+
An app can keep react-native-google-mobile-ads for its other ads, consent and initialization: both
|
|
114
|
+
packages use the one copy of Google's Mobile Ads SDK.
|
|
115
|
+
|
|
116
|
+
- **Versions:** react-native-google-mobile-ads 17.1 or later (the versions for React Native 0.88).
|
|
117
|
+
It pins Google's SDK exactly (17.4.0: iOS 13.10.0, Android 25.5.0), and that pin is what the app
|
|
118
|
+
gets on both platforms: the Rediads pods take Google's SDK 12.0.0 or later, and on Android this
|
|
119
|
+
package's own play-services-ads is only a "prefer", which the pin overrides. A
|
|
120
|
+
react-native-google-mobile-ads release that moves to Google's SDK 14 needs a Rediads release that
|
|
121
|
+
supports it.
|
|
122
|
+
- **App IDs:** give them once, in either plugin. An ID given only to react-native-google-mobile-ads's
|
|
123
|
+
plugin is used by this one too; two different IDs stop `expo prebuild` with an error.
|
|
124
|
+
With react-native-google-mobile-ads in the app the IDs are required: its library manifest
|
|
125
|
+
declares the app ID item, so the Ad Manager flag alone isn't enough.
|
|
126
|
+
- **Android:** keep react-native-google-mobile-ads on Google's classic SDK (its `androidSdk` option
|
|
127
|
+
`"classic"`, the default). Its `"nextgen"` option replaces play-services-ads, which the Rediads SDK
|
|
128
|
+
is built on; the Android build then stops with an error that says so.
|
|
129
|
+
- **Starting Google's SDK:** `mobileAds().initialize()` or `RediadsGAM.start()`, or both.
|
|
130
|
+
- **Test devices:** `RediadsGAM.start({ testDeviceIds })` replaces the list set with
|
|
131
|
+
`mobileAds().setRequestConfiguration()`; set it in one place.
|
|
132
|
+
- **Consent:** `AdsConsent` (Google's UMP) stores the standard IAB consent strings, which the Rediads
|
|
133
|
+
SDK reads. Gather consent before the first ad loads.
|
|
134
|
+
- **Bare React Native apps:** set each app ID once. On Android, react-native-google-mobile-ads's
|
|
135
|
+
library manifest declares the app ID item from its `app.json` key; if the app's
|
|
136
|
+
`AndroidManifest.xml` declares it too, add `tools:replace="android:value"` to that item.
|
|
89
137
|
|
|
90
138
|
## SDK-rendered
|
|
91
139
|
|
package/android/build.gradle
CHANGED
|
@@ -4,21 +4,51 @@ plugins {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
group = 'com.rediads.reactnative.gam'
|
|
7
|
-
version = '0.1.0
|
|
7
|
+
version = '0.1.0'
|
|
8
8
|
|
|
9
9
|
android {
|
|
10
10
|
namespace "com.rediads.reactnative.gam"
|
|
11
11
|
defaultConfig {
|
|
12
12
|
versionCode 1
|
|
13
|
-
versionName "0.1.0
|
|
13
|
+
versionName "0.1.0"
|
|
14
|
+
// Ships in the package and applies to the app's release build (R8): see the file.
|
|
15
|
+
consumerProguardFiles 'consumer-rules.pro'
|
|
14
16
|
}
|
|
15
17
|
lintOptions {
|
|
16
18
|
abortOnError false
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
// react-native-google-mobile-ads can switch Android to Google's Next-Gen SDK (its androidSdk option
|
|
23
|
+
// "nextgen", which sets this Gradle property). That SDK replaces play-services-ads, which Google then
|
|
24
|
+
// asks apps to exclude from every dependency, while the Rediads SDK's classes and custom events are
|
|
25
|
+
// built on play-services-ads: the two can't be in one app.
|
|
26
|
+
if ((findProperty('RNGMA_ANDROID_BACKEND') ?: 'classic').toString().toLowerCase() == 'nextgen') {
|
|
27
|
+
throw new GradleException(
|
|
28
|
+
"@rediads/react-native-ads-gam needs Google's Mobile Ads SDK (play-services-ads), but react-native-google-mobile-ads " +
|
|
29
|
+
"is set to Google's Next-Gen SDK (RNGMA_ANDROID_BACKEND=nextgen). Use its classic SDK: " +
|
|
30
|
+
"androidSdk \"classic\" (the default) in its config plugin."
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Google's Mobile Ads SDK (play-services-ads). The Rediads SDK doesn't bring it (since 0.1.0): the app
|
|
35
|
+
// keeps its own version, and Rediads never raises it. react-native-google-mobile-ads, or the app's own
|
|
36
|
+
// dependency, decides the version. When nothing else in the app asks for play-services-ads (an Expo app
|
|
37
|
+
// with only the Rediads packages), this package adds the version below as a "prefer", the weakest kind
|
|
38
|
+
// in Gradle: any other declaration wins over it, an older one too. Supported: 23.0.0 or newer. The
|
|
39
|
+
// Gradle property rediadsGoogleMobileAdsVersion (the config plugin's androidGoogleMobileAdsVersion
|
|
40
|
+
// option) prefers another version, or "none" adds nothing.
|
|
41
|
+
def googleMobileAdsVersion = (findProperty('rediadsGoogleMobileAdsVersion') ?: '25.5.0').toString()
|
|
42
|
+
|
|
20
43
|
dependencies {
|
|
21
|
-
// The Rediads SDK's GAM classes (SDK-rendered and bidding only), from Maven Central
|
|
22
|
-
//
|
|
23
|
-
implementation 'com.rediads:rediads-gam:0.1.
|
|
44
|
+
// The Rediads SDK's GAM classes (SDK-rendered and bidding only), from Maven Central. Same SDK
|
|
45
|
+
// version as @rediads/react-native-ads.
|
|
46
|
+
implementation 'com.rediads:rediads-gam:0.1.1'
|
|
47
|
+
if (googleMobileAdsVersion == 'none') {
|
|
48
|
+
compileOnly 'com.google.android.gms:play-services-ads:23.0.0'
|
|
49
|
+
} else {
|
|
50
|
+
implementation('com.google.android.gms:play-services-ads') {
|
|
51
|
+
version { prefer googleMobileAdsVersion }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
24
54
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Google's Mobile Ads SDK (25.5.0, for example) brings WorkManager 2.7.0 and Room 2.2.5, whose own rule
|
|
2
|
+
# keeps RoomDatabase subclasses but not their constructors. R8 full mode (the default since AGP 8) then
|
|
3
|
+
# removes WorkDatabase_Impl's constructor, and a release build crashes at start in WorkManagerInitializer
|
|
4
|
+
# ("Failed to create an instance of androidx.work.impl.WorkDatabase"). Room creates its databases by
|
|
5
|
+
# reflection. The Rediads Android SDK carries the same rule since 0.1.0 (0.1.0-beta1 didn't); it stays
|
|
6
|
+
# here too, as it costs nothing.
|
|
7
|
+
-keep class * extends androidx.room.RoomDatabase { <init>(); }
|
package/build/RediadsGAM.js
CHANGED
|
@@ -11,7 +11,7 @@ let startPromise = null;
|
|
|
11
11
|
*/
|
|
12
12
|
export const RediadsGAM = {
|
|
13
13
|
/** This package's version. */
|
|
14
|
-
PACKAGE_VERSION: '0.1.0
|
|
14
|
+
PACKAGE_VERSION: '0.1.0',
|
|
15
15
|
/** False in Expo Go, on web and in builds made before this package was added. */
|
|
16
16
|
isAvailable: native != null,
|
|
17
17
|
/** Google Mobile Ads SDK version, or null when the module isn't in this build. */
|
|
@@ -83,8 +83,16 @@ class GAMBiddingOnlyFullScreenAd {
|
|
|
83
83
|
}
|
|
84
84
|
/** @internal */
|
|
85
85
|
emit(event) {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
// A listener that throws must not stop the others, nor reach the native event callback: an uncaught
|
|
87
|
+
// error there closes a release build.
|
|
88
|
+
for (const listener of [...this.listeners]) {
|
|
89
|
+
try {
|
|
90
|
+
listener(event);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error('[Rediads] An ad listener threw:', error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
/**
|
|
@@ -91,8 +91,16 @@ class GAMFullScreenAd {
|
|
|
91
91
|
}
|
|
92
92
|
/** @internal */
|
|
93
93
|
emit(event) {
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
// A listener that throws must not stop the others, nor reach the native event callback: an uncaught
|
|
95
|
+
// error there closes a release build.
|
|
96
|
+
for (const listener of [...this.listeners]) {
|
|
97
|
+
try {
|
|
98
|
+
listener(event);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.error('[Rediads] An ad listener threw:', error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
/**
|
|
@@ -16,13 +16,15 @@ Pod::Spec.new do |s|
|
|
|
16
16
|
s.static_framework = true
|
|
17
17
|
|
|
18
18
|
s.dependency 'ExpoModulesCore'
|
|
19
|
-
# The Rediads SDK's GAM classes (SDK-rendered and bidding only); they
|
|
19
|
+
# The Rediads SDK's GAM classes (SDK-rendered and bidding only); they need Google's Mobile Ads SDK.
|
|
20
20
|
# Binary pods from Rediads' pod list (github.com/rediads-hq/rediads-ios), which the config plugins
|
|
21
21
|
# add as a Podfile source; see README.md for bare React Native. Same SDK version as
|
|
22
22
|
# @rediads/react-native-ads.
|
|
23
|
-
s.dependency 'RediadsGAM', '0.1.
|
|
24
|
-
s.dependency 'RediadsDisplay', '0.1.
|
|
25
|
-
s
|
|
23
|
+
s.dependency 'RediadsGAM', '0.1.4'
|
|
24
|
+
s.dependency 'RediadsDisplay', '0.1.4'
|
|
25
|
+
# Google's Mobile Ads SDK: the app's own version (react-native-google-mobile-ads pins one), 12.0.0
|
|
26
|
+
# or newer, as the Rediads pods ask. Never raised by us: with nothing pinned, CocoaPods takes the newest.
|
|
27
|
+
s.dependency 'Google-Mobile-Ads-SDK', '>= 12.0.0'
|
|
26
28
|
|
|
27
29
|
s.pod_target_xcconfig = {
|
|
28
30
|
'DEFINES_MODULE' => 'YES',
|
|
@@ -59,6 +59,7 @@ public class RediadsGAMModule: Module {
|
|
|
59
59
|
|
|
60
60
|
AsyncFunction("loadInterstitial") {
|
|
61
61
|
(adId: Int, placement: String, adUnitId: String, format: String, promise: Promise) in
|
|
62
|
+
self.ads.removeValue(forKey: adId)?.discard()
|
|
62
63
|
let slot = GAMFullScreenSlot(placement: placement, send: self.forward(adId))
|
|
63
64
|
self.ads[adId] = slot
|
|
64
65
|
let loader = RediadsGAMInterstitialBiddingOnly(placement: placement, format: Self.format(format))
|
|
@@ -82,6 +83,7 @@ public class RediadsGAMModule: Module {
|
|
|
82
83
|
}.runOnQueue(.main)
|
|
83
84
|
|
|
84
85
|
AsyncFunction("loadRewarded") { (adId: Int, placement: String, adUnitId: String, promise: Promise) in
|
|
86
|
+
self.ads.removeValue(forKey: adId)?.discard()
|
|
85
87
|
let slot = GAMFullScreenSlot(placement: placement, send: self.forward(adId))
|
|
86
88
|
self.ads[adId] = slot
|
|
87
89
|
let loader = RediadsGAMRewardedBiddingOnly(placement: placement)
|
|
@@ -119,7 +121,7 @@ public class RediadsGAMModule: Module {
|
|
|
119
121
|
}.runOnQueue(.main)
|
|
120
122
|
|
|
121
123
|
AsyncFunction("destroy") { (adId: Int) in
|
|
122
|
-
self.ads
|
|
124
|
+
self.ads.removeValue(forKey: adId)?.discard()
|
|
123
125
|
}.runOnQueue(.main)
|
|
124
126
|
|
|
125
127
|
View(RediadsGAMBannerSlot.self) {
|
|
@@ -198,18 +200,30 @@ final class GAMFullScreenSlot: NSObject, FullScreenContentDelegate {
|
|
|
198
200
|
var interstitial: AdManagerInterstitialAd?
|
|
199
201
|
var rewarded: GoogleMobileAds.RewardedAd?
|
|
200
202
|
private var shown = false
|
|
203
|
+
private var discarded = false
|
|
201
204
|
|
|
202
205
|
init(placement: String, send: @escaping ([String: Any]) -> Void) {
|
|
203
206
|
self.placement = placement
|
|
204
207
|
forward = send
|
|
205
208
|
}
|
|
206
209
|
|
|
210
|
+
/// Stops this ad's events, as Android's `destroy` does: a load under an ID in use (JavaScript reuses an
|
|
211
|
+
/// ad's ID when it loads again) replaces the slot, and none of the old one's events (a late `loaded`, the
|
|
212
|
+
/// `dismissed` of an ad still on screen) reach JavaScript as the new ad's. A load in flight still
|
|
213
|
+
/// resolves its own promise.
|
|
214
|
+
func discard() {
|
|
215
|
+
discarded = true
|
|
216
|
+
interstitial?.fullScreenContentDelegate = nil
|
|
217
|
+
rewarded?.fullScreenContentDelegate = nil
|
|
218
|
+
}
|
|
219
|
+
|
|
207
220
|
var isReady: Bool {
|
|
208
221
|
!shown && (interstitial != nil || rewarded != nil)
|
|
209
222
|
}
|
|
210
223
|
|
|
211
224
|
/// Sends an event; nil values are left out.
|
|
212
225
|
func send(_ payload: [String: Any?]) {
|
|
226
|
+
guard !discarded else { return }
|
|
213
227
|
var event: [String: Any] = ["placement": placement]
|
|
214
228
|
for (key, value) in payload {
|
|
215
229
|
if let value { event[key] = value }
|
|
@@ -18,6 +18,7 @@ public class RediadsGAMRenderedModule: Module {
|
|
|
18
18
|
|
|
19
19
|
AsyncFunction("loadInterstitial") {
|
|
20
20
|
(adId: Int, placement: String, adUnitId: String, format: String, promise: Promise) in
|
|
21
|
+
self.discard(adId)
|
|
21
22
|
let ad = RediadsGAMInterstitial(
|
|
22
23
|
placement: placement, gamAdUnitID: adUnitId, format: RediadsGAMModule.format(format))
|
|
23
24
|
ad.onEvent = self.forward(adId) { [weak ad] in ad?.lastRenderer ?? RediadsGAMRenderer.none }
|
|
@@ -30,6 +31,7 @@ public class RediadsGAMRenderedModule: Module {
|
|
|
30
31
|
AsyncFunction("loadRewarded") {
|
|
31
32
|
(adId: Int, placement: String, adUnitId: String, rewardType: String, rewardAmount: Int,
|
|
32
33
|
format: String, displaySeconds: Int, promise: Promise) in
|
|
34
|
+
self.discard(adId)
|
|
33
35
|
let ad = RediadsGAMRewarded(
|
|
34
36
|
placement: placement,
|
|
35
37
|
gamAdUnitID: adUnitId,
|
|
@@ -79,7 +81,7 @@ public class RediadsGAMRenderedModule: Module {
|
|
|
79
81
|
}.runOnQueue(.main)
|
|
80
82
|
|
|
81
83
|
AsyncFunction("destroy") { (adId: Int) in
|
|
82
|
-
self.
|
|
84
|
+
self.discard(adId)
|
|
83
85
|
}.runOnQueue(.main)
|
|
84
86
|
|
|
85
87
|
View(RediadsGAMRenderedBannerSlot.self) {
|
|
@@ -111,6 +113,17 @@ public class RediadsGAMRenderedModule: Module {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
|
|
116
|
+
/// Lets go of the ad under this ID, as Android's `discard` does: a load under an ID in use (JavaScript
|
|
117
|
+
/// reuses an ad's ID when it loads again) replaces the old ad, and none of the old ad's events reach
|
|
118
|
+
/// JavaScript as the new ad's.
|
|
119
|
+
private func discard(_ adId: Int) {
|
|
120
|
+
switch self.ads.removeValue(forKey: adId) {
|
|
121
|
+
case let ad as RediadsGAMInterstitial: ad.onEvent = nil
|
|
122
|
+
case let ad as RediadsGAMRewarded: ad.onEvent = nil
|
|
123
|
+
default: break
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
114
127
|
/// Sends an ad's events to JavaScript under its ID; `loaded` says who renders it.
|
|
115
128
|
private func forward(_ adId: Int, renderer: @escaping () -> RediadsGAMRenderer) -> (RediadsAdEvent) -> Void {
|
|
116
129
|
return { [weak self] event in
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rediads/react-native-ads-gam",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Rediads bids in Google Ad Manager for React Native apps: SDK-rendered (GAM decides, the Rediads SDK draws a Rediads win) or bidding only (the hb_ keys for your GAM requests, GAM draws).",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"ios/*.podspec",
|
|
11
11
|
"ios/*.swift",
|
|
12
12
|
"android/build.gradle",
|
|
13
|
+
"android/consumer-rules.pro",
|
|
13
14
|
"android/src/main/",
|
|
14
15
|
"plugin/",
|
|
15
16
|
"app.plugin.js",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"license": "Apache-2.0",
|
|
40
41
|
"homepage": "https://rediads.com",
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@rediads/react-native-ads": "0.1.0
|
|
43
|
+
"@rediads/react-native-ads": "0.1.0",
|
|
43
44
|
"@types/react": "~19.3.0",
|
|
44
45
|
"eslint": "~9.39.4",
|
|
45
46
|
"eslint-config-universe": "^16.1.2",
|
|
@@ -50,7 +51,7 @@
|
|
|
50
51
|
"typescript": "~6.0.3"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
|
-
"@rediads/react-native-ads": "0.1.0
|
|
54
|
+
"@rediads/react-native-ads": "0.1.0",
|
|
54
55
|
"expo": ">=58.0.0",
|
|
55
56
|
"react": "*",
|
|
56
57
|
"react-native": "*"
|
package/plugin/withRediadsGAM.js
CHANGED
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
* // com.google.android.gms.ads.AD_MANAGER_APP), which Google's SDK accepts instead.
|
|
11
11
|
* iosAppId: 'ca-app-pub-XXXX~YYYY',
|
|
12
12
|
* androidAppId: 'ca-app-pub-XXXX~ZZZZ',
|
|
13
|
+
* // Optional, Android: the Google Mobile Ads SDK (play-services-ads) version to add when nothing
|
|
14
|
+
* // else in the app asks for one; default "25.5.0". The app's own version, or
|
|
15
|
+
* // react-native-google-mobile-ads's, always wins over it. "none" adds nothing.
|
|
16
|
+
* // androidGoogleMobileAdsVersion: '25.5.0',
|
|
13
17
|
* // SDK development only: the same local iOS SDK checkout as for @rediads/react-native-ads.
|
|
14
18
|
* // iosSdkPath: '../rediads-ios-sdk',
|
|
15
19
|
* }],
|
|
@@ -22,10 +26,18 @@
|
|
|
22
26
|
* - Android: the app ID (or the Ad Manager flag) meta-data in AndroidManifest.xml. The SDK comes
|
|
23
27
|
* from Maven Central (or @rediads/react-native-ads's androidMavenRepo option).
|
|
24
28
|
*
|
|
25
|
-
* Other plugins that set the app ID
|
|
26
|
-
*
|
|
29
|
+
* Other plugins that set the app ID must use the same value. An ID given only to
|
|
30
|
+
* react-native-google-mobile-ads's config plugin is used here too, and two different IDs stop the
|
|
31
|
+
* prebuild; with that library in the app the IDs are required (its library manifest declares the app
|
|
32
|
+
* ID item, so the Ad Manager flag alone isn't enough). With @rediads/react-native-ads-admob, give
|
|
33
|
+
* the same IDs here too, so this plugin doesn't mark the app as Ad Manager only.
|
|
27
34
|
*/
|
|
28
|
-
const {
|
|
35
|
+
const {
|
|
36
|
+
addGoogleMetaData,
|
|
37
|
+
addSources,
|
|
38
|
+
googleAppIds,
|
|
39
|
+
withGoogleMobileAdsVersion,
|
|
40
|
+
} = require('@rediads/react-native-ads/app.plugin');
|
|
29
41
|
const {
|
|
30
42
|
AndroidConfig,
|
|
31
43
|
createRunOncePlugin,
|
|
@@ -86,12 +98,18 @@ function checkAppId(name, value) {
|
|
|
86
98
|
|
|
87
99
|
/**
|
|
88
100
|
* @param {import('expo/config').ExpoConfig} config
|
|
89
|
-
* @param {{ iosAppId?: string, androidAppId?: string, iosSdkPath?: string } | undefined} options
|
|
101
|
+
* @param {{ iosAppId?: string, androidAppId?: string, iosSdkPath?: string, androidGoogleMobileAdsVersion?: string } | undefined} options
|
|
90
102
|
*/
|
|
91
103
|
function withRediadsGAM(config, options = {}) {
|
|
92
|
-
const {
|
|
104
|
+
const { iosSdkPath } = options ?? {};
|
|
105
|
+
const { iosAppId, androidAppId, withGoogleMobileAds } = googleAppIds(config, TAG, options ?? {});
|
|
93
106
|
checkAppId('iosAppId', iosAppId);
|
|
94
107
|
checkAppId('androidAppId', androidAppId);
|
|
108
|
+
if (withGoogleMobileAds && (!iosAppId || !androidAppId)) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`${TAG}: react-native-google-mobile-ads is in the app, so Google's SDK needs the app IDs ("ca-app-pub-XXXX~YYYY", from Ad Manager → Inventory → Apps); the Ad Manager flag isn't enough with it. Set iosAppId and androidAppId in its plugin or here.`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
95
113
|
|
|
96
114
|
config = withInfoPlist(config, (config) => {
|
|
97
115
|
const plist = config.modResults;
|
|
@@ -127,13 +145,15 @@ function withRediadsGAM(config, options = {}) {
|
|
|
127
145
|
const { Manifest } = AndroidConfig;
|
|
128
146
|
const application = Manifest.getMainApplicationOrThrow(config.modResults);
|
|
129
147
|
if (androidAppId) {
|
|
130
|
-
|
|
148
|
+
addGoogleMetaData(config.modResults, ANDROID_APP_ID, androidAppId);
|
|
131
149
|
} else if (!Manifest.getMainApplicationMetaDataValue(config.modResults, ANDROID_APP_ID)) {
|
|
132
150
|
Manifest.addMetaDataItemToMainApplication(application, ANDROID_AD_MANAGER_APP, 'true');
|
|
133
151
|
}
|
|
134
152
|
return config;
|
|
135
153
|
});
|
|
136
154
|
|
|
155
|
+
config = withGoogleMobileAdsVersion(config, TAG, options?.androidGoogleMobileAdsVersion);
|
|
156
|
+
|
|
137
157
|
return config;
|
|
138
158
|
}
|
|
139
159
|
|