@rediads/react-native-ads-gam 0.0.0-stage → 0.1.0-beta.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0-beta.1 (not published yet)
4
+
5
+ - SDK-rendered GAM: `RediadsGAMBanner` (320x50, 300x250, refreshes itself), `RediadsGAMInterstitial`
6
+ and `RediadsGAMRewarded` over the SDK's classes of the same names; events say who drew the ad
7
+ (`renderer`: rediads or gam).
8
+ - Bidding only: `RediadsGAM.fetchTargeting` (the `hb_` keys for a GAM request), and
9
+ `RediadsGAMBannerBiddingOnly`, `RediadsGAMInterstitialBiddingOnly`, `RediadsGAMRewardedBiddingOnly`
10
+ over the SDK's RediadsGAM*BiddingOnly classes.
11
+ - Native SDK: iOS pod `RediadsGAM` 0.1.3, Android `com.rediads:rediads-gam:0.1.0-beta1`.
12
+ - `RediadsGAM.start`, and a config plugin that sets the app ID (or marks an Ad Manager app) and adds
13
+ Rediads' pod list as a Podfile source; `iosSdkPath` takes the pods from a local SDK checkout
14
+ instead (SDK development).
15
+ - 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,183 @@
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
+ | Works with react-native-google-mobile-ads | No (the SDK loads GAM) | 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
+ This is a **beta** (`0.1.0-beta.1`): install it with the `beta` tag.
34
+
35
+ ## Requirements
36
+
37
+ - `@rediads/react-native-ads` of the same version (it starts the Rediads SDK).
38
+ - 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, Android 7.0 (API 24) or later, and a development build (not Expo Go).
40
+
41
+ ## Install
42
+
43
+ ### Expo apps
44
+
45
+ ```sh
46
+ npm install @rediads/react-native-ads@beta @rediads/react-native-ads-gam@beta
47
+ ```
48
+
49
+ In `app.json`:
50
+
51
+ ```json
52
+ "plugins": [
53
+ "@rediads/react-native-ads",
54
+ ["@rediads/react-native-ads-gam", {
55
+ "iosAppId": "ca-app-pub-XXXX~YYYY",
56
+ "androidAppId": "ca-app-pub-XXXX~ZZZZ"
57
+ }]
58
+ ]
59
+ ```
60
+
61
+ Then a development build: `npx expo prebuild --clean`, then `npx expo run:ios` and
62
+ `npx expo run:android`, or `eas build --profile development`.
63
+
64
+ - The app IDs (Ad Manager → Inventory → Apps, or AdMob) are optional: without them the plugin marks
65
+ the app as an Ad Manager app (`GADIsAdManagerApp`, `com.google.android.gms.ads.AD_MANAGER_APP`),
66
+ which Google's SDK accepts instead of an ID. If another plugin sets the app ID
67
+ (react-native-google-mobile-ads, `@rediads/react-native-ads-admob`), give the same ID here.
68
+ - Like `@rediads/react-native-ads`, the plugin adds Rediads' pod list to the Podfile sources (once).
69
+ Android needs nothing more: the SDK is on Maven Central.
70
+
71
+ ### Bare React Native apps
72
+
73
+ 1. Set up `@rediads/react-native-ads` first (Expo modules, the two Podfile `source` lines; see its
74
+ README).
75
+ 2. `npm install @rediads/react-native-ads-gam@beta`
76
+ 3. **iOS:** in `Info.plist`, `GADApplicationIdentifier` = your app ID, or `GADIsAdManagerApp` = YES;
77
+ and Google's SKAdNetwork ID `cstr6suwn9.skadnetwork` in `SKAdNetworkItems`. Then
78
+ `cd ios && pod install`.
79
+ 4. **Android:** in `AndroidManifest.xml`, inside `<application>`, either
80
+ `<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-XXXX~ZZZZ"/>`
81
+ or `<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true"/>`.
82
+
83
+ ### What gets installed
84
+
85
+ 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.3 (with `RediadsGAMEventHandlers`
87
+ and Google's Mobile Ads SDK 13 or later), on Android `com.rediads:rediads-gam:0.1.0-beta1` (with its
88
+ event handlers and Google's SDK).
89
+
90
+ ## SDK-rendered
91
+
92
+ ```tsx
93
+ import { RediadsAds } from '@rediads/react-native-ads';
94
+ import { RediadsGAM, RediadsGAMBanner, RediadsGAMInterstitial, RediadsGAMRewarded } from '@rediads/react-native-ads-gam';
95
+
96
+ await RediadsAds.start({ accountId: 'YOUR_ACCOUNT_ID' });
97
+ await RediadsGAM.start(); // Google's SDK; skip if another library starts it
98
+
99
+ // Refreshes itself every 60 s (refreshInterval: 15 to 120), each time with a new auction
100
+ <RediadsGAMBanner placement="home_mrec" adUnitId="/NETWORK_CODE/home_mrec" size="300x250"
101
+ format="video" onAdEvent={(e) => e.type === 'loaded' && console.log('drawn by', e.renderer)} />
102
+
103
+ const interstitial = new RediadsGAMInterstitial('level_end', '/NETWORK_CODE/level_end');
104
+ if ((await interstitial.load()) === null) await interstitial.show(); // shows whichever ad won
105
+
106
+ const rewarded = new RediadsGAMRewarded('extra_life', '/NETWORK_CODE/extra_life',
107
+ { type: 'lives', amount: 1 }, { format: 'video' });
108
+ rewarded.addListener((e) => { if (e.type === 'rewarded') grantLives(e.reward!.amount); }); // your reward
109
+ ```
110
+
111
+ - Events are those of `@rediads/react-native-ads` (`loaded`, `displayed`, `failed`, `clicked`,
112
+ `presented`, `dismissed`, `leftApplication`, `rewarded`), whichever ad won. `loaded` carries
113
+ `renderer`: `rediads` when a Rediads line item won and the Rediads SDK draws the ad, `gam` when GAM's
114
+ demand won and Google's view shows it. Full-screen ads also have `renderer()`.
115
+ - Rewarded hands back **your** reward once, whoever won: a Rediads ad by the Rediads rules (video at
116
+ completion, display after `displaySeconds`), GAM's when Google reports it. The GAM ad unit must be a
117
+ rewarded ad unit whose Rediads line items use Prebid's rewarded app-event VAST.
118
+
119
+ ## Bidding only
120
+
121
+ 1. **Only the keys**, for apps that already load GAM ads with react-native-google-mobile-ads (or
122
+ another library). Its request options take custom targeting, so the keys go straight in:
123
+
124
+ ```tsx
125
+ import { RediadsGAM } from '@rediads/react-native-ads-gam';
126
+ import { GAMBannerAd, BannerAdSize } from 'react-native-google-mobile-ads';
127
+
128
+ const { targeting, error } = await RediadsGAM.fetchTargeting({ type: 'banner', placement: 'home_mrec', size: '300x250' });
129
+ <GAMBannerAd unitId="/NETWORK_CODE/home_mrec" sizes={[BannerAdSize.MEDIUM_RECTANGLE]}
130
+ requestOptions={{ customTargeting: targeting }} />
131
+
132
+ // Interstitial / rewarded: { type: 'interstitial', placement, format } / { type: 'rewarded', placement }
133
+ ```
134
+
135
+ Load GAM whatever the result (`targeting` is empty without a bid), and fetch again for each request:
136
+ a bid serves once.
137
+
138
+ 2. **GAM ads loaded by this package**, with the SDK's bidding-only classes:
139
+
140
+ ```tsx
141
+ import {
142
+ RediadsGAMBannerBiddingOnly,
143
+ RediadsGAMInterstitialBiddingOnly,
144
+ RediadsGAMRewardedBiddingOnly,
145
+ } from '@rediads/react-native-ads-gam';
146
+
147
+ // Loads once; a new `key` loads a new banner with a new bid
148
+ <RediadsGAMBannerBiddingOnly key={refreshCount} placement="home_mrec" adUnitId="/NETWORK_CODE/home_mrec"
149
+ size="300x250" onAdEvent={(e) => console.log(e)} />
150
+
151
+ const interstitial = new RediadsGAMInterstitialBiddingOnly('level_end', '/NETWORK_CODE/level_end', { format: 'video' });
152
+ if ((await interstitial.load()) === null) await interstitial.show();
153
+
154
+ const rewarded = new RediadsGAMRewardedBiddingOnly('extra_life', '/NETWORK_CODE/extra_life'); // video bids
155
+ rewarded.addListener((e) => { if (e.type === 'rewarded') grantReward(); }); // the GAM ad unit's reward
156
+ ```
157
+
158
+ Events: `bid` (with `targeting`, the keys added, or `error`), `loaded` (with GAM's `lineItemId` and
159
+ `creativeId`), `failed`, `impression`, `clicked`, `presented`, `dismissed`, `rewarded` (with `reward`).
160
+
161
+ ## API
162
+
163
+ | | |
164
+ |---|---|
165
+ | `RediadsGAM.start({ testDeviceIds })` | Starts Google's SDK |
166
+ | `RediadsGAM.fetchTargeting({ type, placement, size, format })` | Bidding only: `{ targeting, error }`; `type` banner, interstitial or rewarded |
167
+ | `RediadsGAM.isAvailable`, `.googleSdkVersion`, `.PACKAGE_VERSION` | |
168
+ | `<RediadsGAMBanner placement adUnitId size format refreshInterval onAdEvent />` | SDK-rendered; 320x50 or 300x250 |
169
+ | `new RediadsGAMInterstitial(placement, adUnitId, { format })` | SDK-rendered: `load()`, `isReady()`, `renderer()`, `show()`, `addListener()`, `destroy()` |
170
+ | `new RediadsGAMRewarded(placement, adUnitId, reward, { format, displaySeconds })` | The same |
171
+ | `<RediadsGAMBannerBiddingOnly placement adUnitId size format onAdEvent />` | Bidding only; loads once |
172
+ | `new RediadsGAMInterstitialBiddingOnly(placement, adUnitId, { format })` | Bidding only: `load()`, `isReady()`, `show()`, `addListener()`, `destroy()` |
173
+ | `new RediadsGAMRewardedBiddingOnly(placement, adUnitId)` | The same; video bids |
174
+
175
+ ## Config plugin options
176
+
177
+ `iosAppId` and `androidAppId` (optional, see above), and, for SDK development only, `iosSdkPath`: a
178
+ local iOS SDK checkout (the same as `@rediads/react-native-ads`'s), from which the `RediadsGAM` and
179
+ `RediadsGAMEventHandlers` pods are then taken by path.
180
+
181
+ ## License
182
+
183
+ Apache-2.0
@@ -0,0 +1,24 @@
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-beta.1'
8
+
9
+ android {
10
+ namespace "com.rediads.reactnative.gam"
11
+ defaultConfig {
12
+ versionCode 1
13
+ versionName "0.1.0-beta.1"
14
+ }
15
+ lintOptions {
16
+ abortOnError false
17
+ }
18
+ }
19
+
20
+ dependencies {
21
+ // The Rediads SDK's GAM classes (SDK-rendered and bidding only), from Maven Central; they bring
22
+ // Google's Mobile Ads SDK. Same SDK version as @rediads/react-native-ads.
23
+ implementation 'com.rediads:rediads-gam:0.1.0-beta1'
24
+ }
@@ -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
+ }