@rediads/react-native-ads-gam 0.0.0-stage → 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.
Files changed (34) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/LICENSE +201 -0
  3. package/README.md +230 -2
  4. package/android/build.gradle +54 -0
  5. package/android/consumer-rules.pro +7 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMBannerSlot.kt +99 -0
  8. package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMModule.kt +306 -0
  9. package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMRenderedModule.kt +233 -0
  10. package/app.plugin.js +2 -0
  11. package/build/RediadsGAM.d.ts +46 -0
  12. package/build/RediadsGAM.js +66 -0
  13. package/build/RediadsGAMBanner.d.ts +26 -0
  14. package/build/RediadsGAMBanner.js +40 -0
  15. package/build/RediadsGAMBannerBiddingOnly.d.ts +23 -0
  16. package/build/RediadsGAMBannerBiddingOnly.js +39 -0
  17. package/build/RediadsGAMBiddingOnlyFullScreenAd.d.ts +59 -0
  18. package/build/RediadsGAMBiddingOnlyFullScreenAd.js +128 -0
  19. package/build/RediadsGAMFullScreenAd.d.ts +70 -0
  20. package/build/RediadsGAMFullScreenAd.js +140 -0
  21. package/build/index.d.ts +6 -0
  22. package/build/index.js +7 -0
  23. package/build/native.d.ts +45 -0
  24. package/build/native.js +18 -0
  25. package/build/renderedNative.d.ts +34 -0
  26. package/build/renderedNative.js +15 -0
  27. package/build/types.d.ts +77 -0
  28. package/build/types.js +1 -0
  29. package/expo-module.config.json +18 -0
  30. package/ios/RediadsAdsGAM.podspec +34 -0
  31. package/ios/RediadsGAMModule.swift +355 -0
  32. package/ios/RediadsGAMRenderedModule.swift +208 -0
  33. package/package.json +57 -4
  34. package/plugin/withRediadsGAM.js +161 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
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)
33
+
34
+ - SDK-rendered GAM: `RediadsGAMBanner` (320x50, 300x250, refreshes itself), `RediadsGAMInterstitial`
35
+ and `RediadsGAMRewarded` over the SDK's classes of the same names; events say who drew the ad
36
+ (`renderer`: rediads or gam).
37
+ - Bidding only: `RediadsGAM.fetchTargeting` (the `hb_` keys for a GAM request), and
38
+ `RediadsGAMBannerBiddingOnly`, `RediadsGAMInterstitialBiddingOnly`, `RediadsGAMRewardedBiddingOnly`
39
+ over the SDK's RediadsGAM*BiddingOnly classes.
40
+ - Native SDK: iOS pod `RediadsGAM` 0.1.3, Android `com.rediads:rediads-gam:0.1.0-beta1`.
41
+ - `RediadsGAM.start`, and a config plugin that sets the app ID (or marks an Ad Manager app) and adds
42
+ Rediads' pod list as a Podfile source; `iosSdkPath` takes the pods from a local SDK checkout
43
+ instead (SDK development).
44
+ - Needs `@rediads/react-native-ads` 0.1.0-beta.1.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,231 @@
1
- # Temporary Holding Version
1
+ # @rediads/react-native-ads-gam
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Rediads bids in Google Ad Manager (GAM) for React Native apps on iOS and Android (Expo, or bare with
4
+ Expo modules support). Before each GAM request the package runs the Rediads auction and adds the bid's
5
+ keys to the request (`hb_pb` price bucket, `hb_bidder`, `hb_cache_id`, ...). GAM runs its own auction
6
+ and decides. Two modes, per slot:
7
+
8
+ | | SDK-rendered (`RediadsGAMBanner`, `RediadsGAMInterstitial`, `RediadsGAMRewarded`) | Bidding only (`RediadsGAM.fetchTargeting`, `RediadsGAM*BiddingOnly`) |
9
+ |---|---|---|
10
+ | Who draws a Rediads win | **The Rediads SDK**, with Rediads trackers, MRAID and video | GAM: the Prebid Universal Creative loads the bid from the Rediads cache |
11
+ | Rediads impression and viewability | Yes | Not yet |
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
+ | Banner refresh | Automatic (`refreshInterval`) | Load again (a new `key`) |
14
+ | Loads GAM through react-native-google-mobile-ads | No (the SDK loads GAM; both can be in one app) | Yes, through `fetchTargeting` |
15
+
16
+ Every request from the SDK-rendered classes carries `rediads_render=sdk`.
17
+
18
+ ```tsx
19
+ import { RediadsAds } from '@rediads/react-native-ads';
20
+ import { RediadsGAM, RediadsGAMBanner, RediadsGAMInterstitial } from '@rediads/react-native-ads-gam';
21
+
22
+ await RediadsAds.start({ accountId: 'YOUR_ACCOUNT_ID' });
23
+ await RediadsGAM.start();
24
+
25
+ <RediadsGAMBanner placement="home_mrec" adUnitId="/NETWORK_CODE/home_mrec" size="300x250" />;
26
+ const ad = new RediadsGAMInterstitial('level_end', '/NETWORK_CODE/level_end');
27
+ if ((await ad.load()) === null) await ad.show();
28
+
29
+ // Bidding only, keys for another GAM library
30
+ const { targeting } = await RediadsGAM.fetchTargeting({ type: 'banner', placement: 'home_mrec' });
31
+ ```
32
+
33
+ ## Requirements
34
+
35
+ - `@rediads/react-native-ads` of the same version (it starts the Rediads SDK).
36
+ - Expo SDK 58 or later (React Native 0.88): an Expo app, or a bare React Native app with Expo modules.
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).
45
+
46
+ ## Install
47
+
48
+ ### Expo apps
49
+
50
+ ```sh
51
+ npm install @rediads/react-native-ads @rediads/react-native-ads-gam
52
+ ```
53
+
54
+ In `app.json`:
55
+
56
+ ```json
57
+ "plugins": [
58
+ "@rediads/react-native-ads",
59
+ ["@rediads/react-native-ads-gam", {
60
+ "iosAppId": "ca-app-pub-XXXX~YYYY",
61
+ "androidAppId": "ca-app-pub-XXXX~ZZZZ"
62
+ }]
63
+ ]
64
+ ```
65
+
66
+ Then a development build: `npx expo prebuild --clean`, then `npx expo run:ios` and
67
+ `npx expo run:android`, or `eas build --profile development`.
68
+
69
+ - The app IDs (Ad Manager → Inventory → Apps, or AdMob) are optional: without them the plugin marks
70
+ the app as an Ad Manager app (`GADIsAdManagerApp`, `com.google.android.gms.ads.AD_MANAGER_APP`),
71
+ which Google's SDK accepts instead of an ID. If another plugin sets the app ID
72
+ (react-native-google-mobile-ads, `@rediads/react-native-ads-admob`), give the same ID here.
73
+ - Like `@rediads/react-native-ads`, the plugin adds Rediads' pod list to the Podfile sources (once).
74
+ On Android the SDK comes from Maven Central; for Google's SDK see
75
+ [Google's Mobile Ads SDK](#googles-mobile-ads-sdk).
76
+
77
+ ### Bare React Native apps
78
+
79
+ 1. Set up `@rediads/react-native-ads` first (Expo modules, the two Podfile `source` lines; see its
80
+ README).
81
+ 2. `npm install @rediads/react-native-ads-gam`
82
+ 3. **iOS:** in `Info.plist`, `GADApplicationIdentifier` = your app ID, or `GADIsAdManagerApp` = YES;
83
+ and Google's SKAdNetwork ID `cstr6suwn9.skadnetwork` in `SKAdNetworkItems`. Then
84
+ `cd ios && pod install`.
85
+ 4. **Android:** in `AndroidManifest.xml`, inside `<application>`, either
86
+ `<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-XXXX~ZZZZ"/>`
87
+ or `<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true"/>`.
88
+
89
+ ### What gets installed
90
+
91
+ The JavaScript API (compiled, with types), the native bridge as Swift and Kotlin source, and the
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.
137
+
138
+ ## SDK-rendered
139
+
140
+ ```tsx
141
+ import { RediadsAds } from '@rediads/react-native-ads';
142
+ import { RediadsGAM, RediadsGAMBanner, RediadsGAMInterstitial, RediadsGAMRewarded } from '@rediads/react-native-ads-gam';
143
+
144
+ await RediadsAds.start({ accountId: 'YOUR_ACCOUNT_ID' });
145
+ await RediadsGAM.start(); // Google's SDK; skip if another library starts it
146
+
147
+ // Refreshes itself every 60 s (refreshInterval: 15 to 120), each time with a new auction
148
+ <RediadsGAMBanner placement="home_mrec" adUnitId="/NETWORK_CODE/home_mrec" size="300x250"
149
+ format="video" onAdEvent={(e) => e.type === 'loaded' && console.log('drawn by', e.renderer)} />
150
+
151
+ const interstitial = new RediadsGAMInterstitial('level_end', '/NETWORK_CODE/level_end');
152
+ if ((await interstitial.load()) === null) await interstitial.show(); // shows whichever ad won
153
+
154
+ const rewarded = new RediadsGAMRewarded('extra_life', '/NETWORK_CODE/extra_life',
155
+ { type: 'lives', amount: 1 }, { format: 'video' });
156
+ rewarded.addListener((e) => { if (e.type === 'rewarded') grantLives(e.reward!.amount); }); // your reward
157
+ ```
158
+
159
+ - Events are those of `@rediads/react-native-ads` (`loaded`, `displayed`, `failed`, `clicked`,
160
+ `presented`, `dismissed`, `leftApplication`, `rewarded`), whichever ad won. `loaded` carries
161
+ `renderer`: `rediads` when a Rediads line item won and the Rediads SDK draws the ad, `gam` when GAM's
162
+ demand won and Google's view shows it. Full-screen ads also have `renderer()`.
163
+ - Rewarded hands back **your** reward once, whoever won: a Rediads ad by the Rediads rules (video at
164
+ completion, display after `displaySeconds`), GAM's when Google reports it. The GAM ad unit must be a
165
+ rewarded ad unit whose Rediads line items use Prebid's rewarded app-event VAST.
166
+
167
+ ## Bidding only
168
+
169
+ 1. **Only the keys**, for apps that already load GAM ads with react-native-google-mobile-ads (or
170
+ another library). Its request options take custom targeting, so the keys go straight in:
171
+
172
+ ```tsx
173
+ import { RediadsGAM } from '@rediads/react-native-ads-gam';
174
+ import { GAMBannerAd, BannerAdSize } from 'react-native-google-mobile-ads';
175
+
176
+ const { targeting, error } = await RediadsGAM.fetchTargeting({ type: 'banner', placement: 'home_mrec', size: '300x250' });
177
+ <GAMBannerAd unitId="/NETWORK_CODE/home_mrec" sizes={[BannerAdSize.MEDIUM_RECTANGLE]}
178
+ requestOptions={{ customTargeting: targeting }} />
179
+
180
+ // Interstitial / rewarded: { type: 'interstitial', placement, format } / { type: 'rewarded', placement }
181
+ ```
182
+
183
+ Load GAM whatever the result (`targeting` is empty without a bid), and fetch again for each request:
184
+ a bid serves once.
185
+
186
+ 2. **GAM ads loaded by this package**, with the SDK's bidding-only classes:
187
+
188
+ ```tsx
189
+ import {
190
+ RediadsGAMBannerBiddingOnly,
191
+ RediadsGAMInterstitialBiddingOnly,
192
+ RediadsGAMRewardedBiddingOnly,
193
+ } from '@rediads/react-native-ads-gam';
194
+
195
+ // Loads once; a new `key` loads a new banner with a new bid
196
+ <RediadsGAMBannerBiddingOnly key={refreshCount} placement="home_mrec" adUnitId="/NETWORK_CODE/home_mrec"
197
+ size="300x250" onAdEvent={(e) => console.log(e)} />
198
+
199
+ const interstitial = new RediadsGAMInterstitialBiddingOnly('level_end', '/NETWORK_CODE/level_end', { format: 'video' });
200
+ if ((await interstitial.load()) === null) await interstitial.show();
201
+
202
+ const rewarded = new RediadsGAMRewardedBiddingOnly('extra_life', '/NETWORK_CODE/extra_life'); // video bids
203
+ rewarded.addListener((e) => { if (e.type === 'rewarded') grantReward(); }); // the GAM ad unit's reward
204
+ ```
205
+
206
+ Events: `bid` (with `targeting`, the keys added, or `error`), `loaded` (with GAM's `lineItemId` and
207
+ `creativeId`), `failed`, `impression`, `clicked`, `presented`, `dismissed`, `rewarded` (with `reward`).
208
+
209
+ ## API
210
+
211
+ | | |
212
+ |---|---|
213
+ | `RediadsGAM.start({ testDeviceIds })` | Starts Google's SDK |
214
+ | `RediadsGAM.fetchTargeting({ type, placement, size, format })` | Bidding only: `{ targeting, error }`; `type` banner, interstitial or rewarded |
215
+ | `RediadsGAM.isAvailable`, `.googleSdkVersion`, `.PACKAGE_VERSION` | |
216
+ | `<RediadsGAMBanner placement adUnitId size format refreshInterval onAdEvent />` | SDK-rendered; 320x50 or 300x250 |
217
+ | `new RediadsGAMInterstitial(placement, adUnitId, { format })` | SDK-rendered: `load()`, `isReady()`, `renderer()`, `show()`, `addListener()`, `destroy()` |
218
+ | `new RediadsGAMRewarded(placement, adUnitId, reward, { format, displaySeconds })` | The same |
219
+ | `<RediadsGAMBannerBiddingOnly placement adUnitId size format onAdEvent />` | Bidding only; loads once |
220
+ | `new RediadsGAMInterstitialBiddingOnly(placement, adUnitId, { format })` | Bidding only: `load()`, `isReady()`, `show()`, `addListener()`, `destroy()` |
221
+ | `new RediadsGAMRewardedBiddingOnly(placement, adUnitId)` | The same; video bids |
222
+
223
+ ## Config plugin options
224
+
225
+ `iosAppId` and `androidAppId` (optional, see above), and, for SDK development only, `iosSdkPath`: a
226
+ local iOS SDK checkout (the same as `@rediads/react-native-ads`'s), from which the `RediadsGAM` and
227
+ `RediadsGAMEventHandlers` pods are then taken by path.
228
+
229
+ ## License
230
+
231
+ Apache-2.0
@@ -0,0 +1,54 @@
1
+ plugins {
2
+ id 'com.android.library'
3
+ id 'expo-module-gradle-plugin'
4
+ }
5
+
6
+ group = 'com.rediads.reactnative.gam'
7
+ version = '0.1.0'
8
+
9
+ android {
10
+ namespace "com.rediads.reactnative.gam"
11
+ defaultConfig {
12
+ versionCode 1
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'
16
+ }
17
+ lintOptions {
18
+ abortOnError false
19
+ }
20
+ }
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
+
43
+ dependencies {
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
+ }
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>(); }
@@ -0,0 +1,2 @@
1
+ <manifest>
2
+ </manifest>
@@ -0,0 +1,99 @@
1
+ package com.rediads.reactnative.gam
2
+
3
+ import android.content.Context
4
+ import android.view.Gravity
5
+ import android.widget.LinearLayout
6
+ import com.google.android.gms.ads.AdListener
7
+ import com.google.android.gms.ads.AdSize
8
+ import com.google.android.gms.ads.LoadAdError
9
+ import com.google.android.gms.ads.admanager.AdManagerAdRequest
10
+ import com.google.android.gms.ads.admanager.AdManagerAdView
11
+ import com.rediads.gam.RediadsGAMBannerBiddingOnly
12
+ import expo.modules.kotlin.AppContext
13
+ import expo.modules.kotlin.viewevent.EventDispatcher
14
+ import expo.modules.kotlin.views.ExpoView
15
+
16
+ /**
17
+ * One GAM banner slot. The banner is made once React has set the props and loaded once; JavaScript gives
18
+ * the view a new key to load a new one (bidding-only banners refresh by loading again).
19
+ */
20
+ class RediadsGAMBannerSlot(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
21
+ // React Native doesn't lay out views added natively; let ExpoView measure the banner.
22
+ override val shouldUseAndroidLayout = true
23
+
24
+ private val onAdEvent by EventDispatcher()
25
+ var placement = ""
26
+ var adUnitId = ""
27
+ var size = "300x250"
28
+ var format = "display"
29
+ private var adView: AdManagerAdView? = null
30
+ private var rediads: RediadsGAMBannerBiddingOnly? = null
31
+
32
+ init {
33
+ gravity = Gravity.CENTER
34
+ }
35
+
36
+ fun loadIfReady() {
37
+ if (rediads != null || placement.isEmpty() || adUnitId.isEmpty()) return
38
+ val adSize = if (size == "320x50") AdSize.BANNER else AdSize.MEDIUM_RECTANGLE
39
+ // The Activity, so a click can open over the app.
40
+ val adView = AdManagerAdView(appContext.currentActivity ?: context)
41
+ adView.setAdSizes(adSize)
42
+ adView.adUnitId = adUnitId
43
+ // Set before RediadsGAMBannerBiddingOnly.load, which puts its stand-in in front and passes calls on.
44
+ adView.adListener = listener
45
+ val density = resources.displayMetrics.density
46
+ addView(
47
+ adView,
48
+ LinearLayout.LayoutParams((adSize.width * density).toInt(), (adSize.height * density).toInt()),
49
+ )
50
+ this.adView = adView
51
+
52
+ val rediads = RediadsGAMBannerBiddingOnly(
53
+ placement,
54
+ RediadsGAMModule.bannerSize(size),
55
+ RediadsGAMModule.format(format),
56
+ )
57
+ this.rediads = rediads
58
+ var builder: AdManagerAdRequest.Builder? = null
59
+ rediads.load(adView, { builder = it }) { error ->
60
+ send(
61
+ mapOf(
62
+ "type" to "bid",
63
+ "targeting" to RediadsGAMModule.rediadsKeys(builder),
64
+ "error" to error?.message,
65
+ ),
66
+ )
67
+ }
68
+ }
69
+
70
+ fun destroy() {
71
+ rediads?.destroy()
72
+ rediads = null
73
+ adView?.destroy()
74
+ adView = null
75
+ }
76
+
77
+ private fun send(payload: Map<String, Any?>) {
78
+ onAdEvent(payload.filterValues { it != null }.mapValues { it.value!! } + ("placement" to placement))
79
+ }
80
+
81
+ /** Google's events for the ad GAM served. */
82
+ private val listener = object : AdListener() {
83
+ override fun onAdLoaded() {
84
+ send(mapOf("type" to "loaded") + RediadsGAMModule.describe(adView?.responseInfo))
85
+ }
86
+
87
+ override fun onAdFailedToLoad(error: LoadAdError) {
88
+ send(mapOf("type" to "failed", "error" to error.message))
89
+ }
90
+
91
+ override fun onAdImpression() = send(mapOf("type" to "impression"))
92
+
93
+ override fun onAdClicked() = send(mapOf("type" to "clicked"))
94
+
95
+ override fun onAdOpened() = send(mapOf("type" to "presented"))
96
+
97
+ override fun onAdClosed() = send(mapOf("type" to "dismissed"))
98
+ }
99
+ }