react-native-google-mobile-ads 6.3.0 → 7.0.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 (43) hide show
  1. package/RNGoogleMobileAds.podspec +1 -1
  2. package/android/build.gradle +23 -3
  3. package/android/src/main/AndroidManifest.xml +6 -0
  4. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAdHelper.kt +106 -0
  5. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.kt +74 -0
  6. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsFullScreenAdModule.kt +245 -0
  7. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.kt +74 -0
  8. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.kt +74 -0
  9. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.kt +74 -0
  10. package/docs/displaying-ads.mdx +1 -1
  11. package/docs/european-user-consent.mdx +3 -2
  12. package/docs/index.mdx +5 -1
  13. package/docs/migrating-to-v6.mdx +2 -2
  14. package/ios/RNGoogleMobileAds/RNGoogleMobileAds-Bridging-Header.h +5 -0
  15. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +13 -68
  16. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.swift +82 -0
  17. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenAd.swift +208 -0
  18. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.swift +72 -0
  19. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +13 -107
  20. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.swift +119 -0
  21. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +13 -144
  22. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.swift +81 -0
  23. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +13 -143
  24. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.swift +81 -0
  25. package/ios_config.sh +10 -0
  26. package/lib/commonjs/version.js +1 -1
  27. package/lib/commonjs/version.js.map +1 -1
  28. package/lib/module/version.js +1 -1
  29. package/lib/module/version.js.map +1 -1
  30. package/lib/typescript/index.d.ts +1 -1
  31. package/lib/typescript/version.d.ts +1 -1
  32. package/package.json +4 -4
  33. package/src/version.ts +1 -1
  34. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +0 -159
  35. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +0 -178
  36. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.java +0 -199
  37. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.java +0 -176
  38. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.h +0 -29
  39. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +0 -33
  40. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +0 -72
  41. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.h +0 -25
  42. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.h +0 -25
  43. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.h +0 -25
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
18
18
  s.source = { :git => "#{package["repository"]["url"]}.git", :tag => "v#{s.version}" }
19
19
  s.social_media_url = 'http://twitter.com/invertaseio'
20
20
  s.ios.deployment_target = "10.0"
21
- s.source_files = 'ios/**/*.{h,m}'
21
+ s.source_files = 'ios/**/*.{h,m,swift}'
22
22
  s.weak_frameworks = "AppTrackingTransparency"
23
23
 
24
24
  # React Native dependencies
@@ -12,6 +12,7 @@ buildscript {
12
12
 
13
13
  dependencies {
14
14
  classpath("com.android.tools.build:gradle:7.0.4")
15
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.6.10')}"
15
16
  }
16
17
  }
17
18
  }
@@ -19,6 +20,7 @@ buildscript {
19
20
  plugins {
20
21
  id "io.invertase.gradle.build" version "1.5"
21
22
  }
23
+ apply plugin: 'kotlin-android'
22
24
 
23
25
  def packageJson = PackageJson.getForProject(project)
24
26
  def googleMobileAdsVersion = packageJson['sdkVersions']['android']['googleMobileAds']
@@ -53,16 +55,28 @@ project.ext {
53
55
 
54
56
  apply from: file("./app-json.gradle")
55
57
 
56
- def appJSONGoogleMobileAdsAppIDString = ""
58
+ def appJSONGoogleMobileAdsAppIDString
57
59
  def appJSONGoogleMobileAdsDelayAppMeasurementInitBool = false
60
+ def appJSONGoogleMobileAdsOptimizeInitializationBool = true
61
+ def appJSONGoogleMobileAdsOptimizeAdLoadingBool = true
58
62
 
59
63
  if (rootProject.ext.googleMobileAdsJson) {
60
64
  appJSONGoogleMobileAdsAppIDString = rootProject.ext.googleMobileAdsJson.getStringValue("android_app_id", "")
61
65
  appJSONGoogleMobileAdsDelayAppMeasurementInitBool = rootProject.ext.googleMobileAdsJson.isFlagEnabled("delay_app_measurement_init", false)
66
+ appJSONGoogleMobileAdsOptimizeInitializationBool = rootProject.ext.googleMobileAdsJson.isFlagEnabled("optimize_initialization", true)
67
+ appJSONGoogleMobileAdsOptimizeAdLoadingBool = rootProject.ext.googleMobileAdsJson.isFlagEnabled("optimize_ad_loading", true)
62
68
  }
63
69
 
64
70
  if (!appJSONGoogleMobileAdsAppIDString) {
65
- // todo throw a build error?
71
+ println "\n\n\n"
72
+ println "**************************************************************************************************************"
73
+ println "\n\n\n"
74
+ println "ERROR: react-native-google-mobile-ads requires an 'android_app_id' property inside a 'react-native-google-mobile-ads' key in your app.json."
75
+ println " No android_app_id property was found in this location. The native Google Mobile Ads SDK will crash on startup without it."
76
+ println "\n\n\n"
77
+ println "**************************************************************************************************************"
78
+ println "\n\n\n"
79
+ System.exit(1)
66
80
  }
67
81
 
68
82
  android {
@@ -70,7 +84,9 @@ android {
70
84
  multiDexEnabled true
71
85
  manifestPlaceholders = [
72
86
  appJSONGoogleMobileAdsAppID : appJSONGoogleMobileAdsAppIDString,
73
- appJSONGoogleMobileAdsDelayAppMeasurementInit: appJSONGoogleMobileAdsDelayAppMeasurementInitBool
87
+ appJSONGoogleMobileAdsDelayAppMeasurementInit: appJSONGoogleMobileAdsDelayAppMeasurementInitBool,
88
+ appJSONGoogleMobileAdsOptimizeInitialization : appJSONGoogleMobileAdsOptimizeInitializationBool,
89
+ appJSONGoogleMobileAdsOptimizeAdLoading : appJSONGoogleMobileAdsOptimizeAdLoadingBool
74
90
  ]
75
91
  }
76
92
  lintOptions {
@@ -97,3 +113,7 @@ ReactNative.shared.applyPackageVersion()
97
113
  ReactNative.shared.applyDefaultExcludes()
98
114
  ReactNative.module.applyAndroidVersions()
99
115
  ReactNative.module.applyReactNativeDependency("api")
116
+
117
+ def safeExtGet(prop, fallback) {
118
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
119
+ }
@@ -13,5 +13,11 @@
13
13
  <meta-data
14
14
  android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
15
15
  android:value="${appJSONGoogleMobileAdsDelayAppMeasurementInit}"/>
16
+ <meta-data
17
+ android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION"
18
+ android:value="${appJSONGoogleMobileAdsOptimizeInitialization}"/>
19
+ <meta-data
20
+ android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
21
+ android:value="${appJSONGoogleMobileAdsOptimizeAdLoading}"/>
16
22
  </application>
17
23
  </manifest>
@@ -0,0 +1,106 @@
1
+ package io.invertase.googlemobileads
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import android.app.Activity
21
+ import com.google.android.gms.ads.AdLoadCallback
22
+ import com.google.android.gms.ads.FullScreenContentCallback
23
+ import com.google.android.gms.ads.LoadAdError
24
+ import com.google.android.gms.ads.OnUserEarnedRewardListener
25
+ import com.google.android.gms.ads.admanager.AdManagerAdRequest
26
+ import com.google.android.gms.ads.admanager.AdManagerInterstitialAd
27
+ import com.google.android.gms.ads.admanager.AppEventListener
28
+ import com.google.android.gms.ads.appopen.AppOpenAd
29
+ import com.google.android.gms.ads.interstitial.InterstitialAd
30
+ import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
31
+ import com.google.android.gms.ads.rewarded.RewardItem
32
+ import com.google.android.gms.ads.rewarded.RewardedAd
33
+ import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
34
+ import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions
35
+ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd
36
+ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback
37
+
38
+ class ReactNativeGoogleMobileAdsAdHelper<T>(private val ad: T) {
39
+ fun show(activity: Activity, onUserEarnedRewardListener: OnUserEarnedRewardListener?) {
40
+ when (ad) {
41
+ is AppOpenAd, is InterstitialAd -> {
42
+ val method = ad.javaClass.getMethod("show", Activity::class.java)
43
+ method.invoke(ad, activity)
44
+ }
45
+ is RewardedAd, is RewardedInterstitialAd -> {
46
+ val method = ad.javaClass.getMethod(
47
+ "show",
48
+ Activity::class.java,
49
+ OnUserEarnedRewardListener::class.java
50
+ )
51
+ method.invoke(ad, activity, onUserEarnedRewardListener)
52
+ }
53
+ }
54
+ }
55
+
56
+ fun setFullScreenContentCallback(fullScreenContentCallback: FullScreenContentCallback) {
57
+ when (ad) {
58
+ is AppOpenAd, is InterstitialAd, is RewardedAd, is RewardedInterstitialAd -> {
59
+ val method = ad.javaClass.getMethod(
60
+ "setFullScreenContentCallback",
61
+ FullScreenContentCallback::class.java
62
+ )
63
+ method.invoke(ad, fullScreenContentCallback)
64
+ }
65
+ }
66
+ }
67
+
68
+ fun setAppEventListener(appEventListener: AppEventListener) {
69
+ if (ad is AdManagerInterstitialAd) {
70
+ val method = ad.javaClass.getMethod("setAppEventListener", AppEventListener::class.java)
71
+ method.invoke(ad, appEventListener)
72
+ }
73
+ }
74
+
75
+ fun setImmersiveMode(enabled: Boolean) {
76
+ when (ad) {
77
+ is AppOpenAd, is InterstitialAd, is RewardedAd, is RewardedInterstitialAd -> {
78
+ val method = ad.javaClass.getMethod("setImmersiveMode", Boolean::class.javaPrimitiveType)
79
+ method.invoke(ad, enabled)
80
+ }
81
+ }
82
+ }
83
+
84
+ fun setServerSideVerificationOptions(serverSideVerificationOptions: ServerSideVerificationOptions) {
85
+ when (ad) {
86
+ is RewardedAd, is RewardedInterstitialAd -> {
87
+ val method = ad.javaClass.getMethod(
88
+ "setServerSideVerificationOptions",
89
+ ServerSideVerificationOptions::class.java
90
+ )
91
+ method.invoke(ad, serverSideVerificationOptions)
92
+ }
93
+ }
94
+ }
95
+
96
+ val rewardItem: RewardItem
97
+ get() {
98
+ when (ad) {
99
+ is RewardedAd, is RewardedInterstitialAd -> {
100
+ val method = ad.javaClass.getMethod("getRewardItem")
101
+ return method.invoke(ad) as RewardItem
102
+ }
103
+ }
104
+ throw IllegalStateException("Ad type not supported")
105
+ }
106
+ }
@@ -0,0 +1,74 @@
1
+ package io.invertase.googlemobileads
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import android.app.Activity
21
+ import com.facebook.react.bridge.Promise
22
+ import com.facebook.react.bridge.ReactApplicationContext
23
+ import com.facebook.react.bridge.ReactMethod
24
+ import com.facebook.react.bridge.ReadableMap
25
+ import com.google.android.gms.ads.AdLoadCallback
26
+ import com.google.android.gms.ads.LoadAdError
27
+ import com.google.android.gms.ads.admanager.AdManagerAdRequest
28
+ import com.google.android.gms.ads.appopen.AppOpenAd
29
+
30
+ class ReactNativeGoogleMobileAdsAppOpenModule(reactContext: ReactApplicationContext?) :
31
+ ReactNativeGoogleMobileAdsFullScreenAdModule<AppOpenAd>(reactContext, NAME) {
32
+
33
+ override fun getAdEventName(): String {
34
+ return ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_APP_OPEN
35
+ }
36
+
37
+ @ReactMethod
38
+ fun appOpenLoad(requestId: Int, adUnitId: String, adRequestOptions: ReadableMap) {
39
+ load(requestId, adUnitId, adRequestOptions)
40
+ }
41
+
42
+ @ReactMethod
43
+ fun appOpenShow(
44
+ requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
45
+ ) {
46
+ show(requestId, adUnitId, showOptions, promise)
47
+ }
48
+
49
+ override fun loadAd(
50
+ activity: Activity,
51
+ adUnitId: String,
52
+ adRequest: AdManagerAdRequest,
53
+ adLoadCallback: AdLoadCallback<AppOpenAd>
54
+ ) {
55
+ AppOpenAd.load(
56
+ activity,
57
+ adUnitId,
58
+ adRequest,
59
+ AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT,
60
+ object :
61
+ AppOpenAd.AppOpenAdLoadCallback() {
62
+ override fun onAdLoaded(ad: AppOpenAd) {
63
+ adLoadCallback.onAdLoaded(ad)
64
+ }
65
+ override fun onAdFailedToLoad(error: LoadAdError) {
66
+ adLoadCallback.onAdFailedToLoad(error)
67
+ }
68
+ })
69
+ }
70
+
71
+ companion object {
72
+ const val NAME = "RNGoogleMobileAdsAppOpenModule"
73
+ }
74
+ }
@@ -0,0 +1,245 @@
1
+ package io.invertase.googlemobileads
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import android.app.Activity
21
+ import android.util.SparseArray
22
+ import com.facebook.react.bridge.*
23
+ import com.google.android.gms.ads.AdLoadCallback
24
+ import com.google.android.gms.ads.FullScreenContentCallback
25
+ import com.google.android.gms.ads.LoadAdError
26
+ import com.google.android.gms.ads.admanager.AdManagerAdRequest
27
+ import com.google.android.gms.ads.admanager.AdManagerInterstitialAd
28
+ import com.google.android.gms.ads.rewarded.RewardedAd
29
+ import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions
30
+ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd
31
+ import io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_APP_EVENT
32
+ import io.invertase.googlemobileads.common.ReactNativeModule
33
+
34
+ abstract class ReactNativeGoogleMobileAdsFullScreenAdModule<T>(
35
+ reactContext: ReactApplicationContext?,
36
+ moduleName: String
37
+ ) : ReactNativeModule(reactContext, moduleName) {
38
+ private val adArray = SparseArray<T>()
39
+
40
+ abstract fun getAdEventName(): String
41
+
42
+ abstract fun loadAd(
43
+ activity: Activity,
44
+ adUnitId: String,
45
+ adRequest: AdManagerAdRequest,
46
+ adLoadCallback: AdLoadCallback<T>
47
+ )
48
+
49
+ private fun sendAdEvent(
50
+ type: String,
51
+ requestId: Int,
52
+ adUnitId: String,
53
+ error: WritableMap?,
54
+ data: WritableMap?
55
+ ) {
56
+ ReactNativeGoogleMobileAdsCommon.sendAdEvent(
57
+ getAdEventName(),
58
+ requestId,
59
+ type,
60
+ adUnitId,
61
+ error,
62
+ data
63
+ )
64
+ }
65
+
66
+ fun load(
67
+ requestId: Int, adUnitId: String, adRequestOptions: ReadableMap
68
+ ) {
69
+ val activity = currentActivity
70
+ if (activity == null) {
71
+ val error = Arguments.createMap()
72
+ error.putString("code", "null-activity")
73
+ error.putString(
74
+ "message",
75
+ "Ad attempted to load but the current Activity was null."
76
+ )
77
+ sendAdEvent(
78
+ ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_ERROR,
79
+ requestId,
80
+ adUnitId,
81
+ error,
82
+ null
83
+ )
84
+ return
85
+ }
86
+ val adRequest = ReactNativeGoogleMobileAdsCommon.buildAdRequest(adRequestOptions)
87
+ val adLoadCallback = ReactNativeGoogleMobileAdsAdLoadCallback(
88
+ requestId,
89
+ adUnitId,
90
+ adRequestOptions
91
+ )
92
+ activity.runOnUiThread {
93
+ loadAd(
94
+ activity,
95
+ adUnitId,
96
+ adRequest,
97
+ adLoadCallback
98
+ )
99
+ }
100
+ }
101
+
102
+ fun show(
103
+ requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
104
+ ) {
105
+ val activity = currentActivity
106
+ if (activity == null) {
107
+ rejectPromiseWithCodeAndMessage(
108
+ promise,
109
+ "null-activity",
110
+ "Ad attempted to show but the current Activity was null."
111
+ )
112
+ return
113
+ }
114
+ activity.runOnUiThread {
115
+ val ad = adArray[requestId]
116
+ val adHelper = ReactNativeGoogleMobileAdsAdHelper(ad)
117
+
118
+ var immersiveModeEnabled = false
119
+ if (showOptions.hasKey("immersiveModeEnabled")) {
120
+ immersiveModeEnabled = showOptions.getBoolean("immersiveModeEnabled")
121
+ }
122
+ adHelper.setImmersiveMode(immersiveModeEnabled)
123
+
124
+ adHelper.show(activity) { rewardItem ->
125
+ val data = Arguments.createMap()
126
+ data.putString("type", rewardItem.type)
127
+ data.putInt("amount", rewardItem.amount)
128
+ sendAdEvent(
129
+ ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD,
130
+ requestId,
131
+ adUnitId,
132
+ null,
133
+ data
134
+ )
135
+ }
136
+ promise.resolve(null)
137
+ }
138
+ }
139
+
140
+ inner class ReactNativeGoogleMobileAdsAdLoadCallback(
141
+ private val requestId: Int,
142
+ private val adUnitId: String,
143
+ private val adRequestOptions: ReadableMap
144
+ ) : AdLoadCallback<T>() {
145
+ override fun onAdLoaded(ad: T) {
146
+ val adHelper = ReactNativeGoogleMobileAdsAdHelper(ad)
147
+ var eventType = ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_LOADED
148
+ var data: WritableMap? = null
149
+
150
+ if (ad is RewardedAd || ad is RewardedInterstitialAd) {
151
+ eventType = ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED
152
+
153
+ val rewardItem = adHelper.rewardItem
154
+ data = Arguments.createMap()
155
+ data.putString("type", rewardItem.type)
156
+ data.putInt("amount", rewardItem.amount)
157
+
158
+ adRequestOptions.getMap("serverSideVerificationOptions")
159
+ ?.let { serverSideVerificationOptions ->
160
+ val options =
161
+ ServerSideVerificationOptions.Builder()
162
+ serverSideVerificationOptions.getString("userId")?.let {
163
+ options.setUserId(it)
164
+ }
165
+ serverSideVerificationOptions.getString("customData")?.let {
166
+ options.setCustomData(it)
167
+ }
168
+ adHelper.setServerSideVerificationOptions(options.build())
169
+ }
170
+ }
171
+
172
+ if (ad is AdManagerInterstitialAd) {
173
+ adHelper.setAppEventListener { name, eventData ->
174
+ val payload = Arguments.createMap()
175
+ payload.putString("name", name)
176
+ payload.putString("data", eventData)
177
+ sendAdEvent(
178
+ GOOGLE_MOBILE_ADS_EVENT_APP_EVENT,
179
+ requestId,
180
+ adUnitId,
181
+ null,
182
+ payload
183
+ )
184
+ }
185
+ }
186
+
187
+ val fullScreenContentCallback: FullScreenContentCallback =
188
+ object : FullScreenContentCallback() {
189
+ override fun onAdShowedFullScreenContent() {
190
+ sendAdEvent(ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_OPENED)
191
+ }
192
+
193
+ override fun onAdDismissedFullScreenContent() {
194
+ sendAdEvent(ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLOSED)
195
+ }
196
+
197
+ override fun onAdClicked() {
198
+ sendAdEvent(ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLICKED)
199
+ }
200
+
201
+ override fun onAdImpression() {
202
+ // Not Implemented Yet
203
+ }
204
+
205
+ private fun sendAdEvent(type: String) {
206
+ sendAdEvent(
207
+ type,
208
+ requestId,
209
+ adUnitId,
210
+ null,
211
+ null
212
+ )
213
+ }
214
+ }
215
+ adHelper.setFullScreenContentCallback(fullScreenContentCallback)
216
+
217
+ adArray.put(
218
+ requestId,
219
+ ad
220
+ )
221
+ sendAdEvent(
222
+ eventType,
223
+ requestId,
224
+ adUnitId,
225
+ null,
226
+ data
227
+ )
228
+ }
229
+
230
+ override fun onAdFailedToLoad(loadAdError: LoadAdError) {
231
+ val error = Arguments.createMap()
232
+ val codeAndMessage =
233
+ ReactNativeGoogleMobileAdsCommon.getCodeAndMessageFromAdError(loadAdError)
234
+ error.putString("code", codeAndMessage[0])
235
+ error.putString("message", codeAndMessage[1])
236
+ sendAdEvent(
237
+ ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_ERROR,
238
+ requestId,
239
+ adUnitId,
240
+ error,
241
+ null
242
+ )
243
+ }
244
+ }
245
+ }
@@ -0,0 +1,74 @@
1
+ package io.invertase.googlemobileads
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import android.app.Activity
21
+ import com.facebook.react.bridge.Promise
22
+ import com.facebook.react.bridge.ReactApplicationContext
23
+ import com.facebook.react.bridge.ReactMethod
24
+ import com.facebook.react.bridge.ReadableMap
25
+ import com.google.android.gms.ads.AdLoadCallback
26
+ import com.google.android.gms.ads.LoadAdError
27
+ import com.google.android.gms.ads.admanager.AdManagerAdRequest
28
+ import com.google.android.gms.ads.admanager.AdManagerInterstitialAd
29
+ import com.google.android.gms.ads.admanager.AdManagerInterstitialAdLoadCallback
30
+
31
+ class ReactNativeGoogleMobileAdsInterstitialModule(reactContext: ReactApplicationContext?) :
32
+ ReactNativeGoogleMobileAdsFullScreenAdModule<AdManagerInterstitialAd>(reactContext, NAME) {
33
+
34
+ override fun getAdEventName(): String {
35
+ return ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL
36
+ }
37
+
38
+ @ReactMethod
39
+ fun interstitialLoad(requestId: Int, adUnitId: String, adRequestOptions: ReadableMap) {
40
+ load(requestId, adUnitId, adRequestOptions)
41
+ }
42
+
43
+ @ReactMethod
44
+ fun interstitialShow(
45
+ requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
46
+ ) {
47
+ show(requestId, adUnitId, showOptions, promise)
48
+ }
49
+
50
+ override fun loadAd(
51
+ activity: Activity,
52
+ adUnitId: String,
53
+ adRequest: AdManagerAdRequest,
54
+ adLoadCallback: AdLoadCallback<AdManagerInterstitialAd>
55
+ ) {
56
+ AdManagerInterstitialAd.load(
57
+ activity,
58
+ adUnitId,
59
+ adRequest,
60
+ object :
61
+ AdManagerInterstitialAdLoadCallback() {
62
+ override fun onAdLoaded(ad: AdManagerInterstitialAd) {
63
+ adLoadCallback.onAdLoaded(ad)
64
+ }
65
+ override fun onAdFailedToLoad(error: LoadAdError) {
66
+ adLoadCallback.onAdFailedToLoad(error)
67
+ }
68
+ })
69
+ }
70
+
71
+ companion object {
72
+ const val NAME = "RNGoogleMobileAdsInterstitialModule"
73
+ }
74
+ }
@@ -0,0 +1,74 @@
1
+ package io.invertase.googlemobileads
2
+
3
+ /*
4
+ * Copyright (c) 2016-present Invertase Limited & Contributors
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this library except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ */
19
+
20
+ import android.app.Activity
21
+ import com.facebook.react.bridge.Promise
22
+ import com.facebook.react.bridge.ReactApplicationContext
23
+ import com.facebook.react.bridge.ReactMethod
24
+ import com.facebook.react.bridge.ReadableMap
25
+ import com.google.android.gms.ads.AdLoadCallback
26
+ import com.google.android.gms.ads.LoadAdError
27
+ import com.google.android.gms.ads.admanager.AdManagerAdRequest
28
+ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd
29
+ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback
30
+
31
+ class ReactNativeGoogleMobileAdsRewardedInterstitialModule(reactContext: ReactApplicationContext?) :
32
+ ReactNativeGoogleMobileAdsFullScreenAdModule<RewardedInterstitialAd>(reactContext, NAME) {
33
+
34
+ override fun getAdEventName(): String {
35
+ return ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
36
+ }
37
+
38
+ @ReactMethod
39
+ fun rewardedInterstitialLoad(requestId: Int, adUnitId: String, adRequestOptions: ReadableMap) {
40
+ load(requestId, adUnitId, adRequestOptions)
41
+ }
42
+
43
+ @ReactMethod
44
+ fun rewardedInterstitialShow(
45
+ requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
46
+ ) {
47
+ show(requestId, adUnitId, showOptions, promise)
48
+ }
49
+
50
+ override fun loadAd(
51
+ activity: Activity,
52
+ adUnitId: String,
53
+ adRequest: AdManagerAdRequest,
54
+ adLoadCallback: AdLoadCallback<RewardedInterstitialAd>
55
+ ) {
56
+ RewardedInterstitialAd.load(
57
+ activity,
58
+ adUnitId,
59
+ adRequest,
60
+ object :
61
+ RewardedInterstitialAdLoadCallback() {
62
+ override fun onAdLoaded(ad: RewardedInterstitialAd) {
63
+ adLoadCallback.onAdLoaded(ad)
64
+ }
65
+ override fun onAdFailedToLoad(error: LoadAdError) {
66
+ adLoadCallback.onAdFailedToLoad(error)
67
+ }
68
+ })
69
+ }
70
+
71
+ companion object {
72
+ const val NAME = "RNGoogleMobileAdsRewardedInterstitialModule"
73
+ }
74
+ }