react-native-google-mobile-ads 6.2.4 → 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 (59) 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/ReactNativeGoogleMobileAdsCommon.java +5 -0
  7. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsFullScreenAdModule.kt +245 -0
  8. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.kt +74 -0
  9. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +2 -1
  10. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.kt +74 -0
  11. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.kt +74 -0
  12. package/docs/displaying-ads.mdx +2 -2
  13. package/docs/european-user-consent.mdx +3 -2
  14. package/docs/index.mdx +5 -1
  15. package/docs/migrating-to-v6.mdx +2 -2
  16. package/ios/RNGoogleMobileAds/RNGoogleMobileAds-Bridging-Header.h +5 -0
  17. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +13 -68
  18. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.swift +82 -0
  19. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +4 -0
  20. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenAd.swift +208 -0
  21. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.swift +72 -0
  22. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +13 -107
  23. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.swift +119 -0
  24. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m +2 -1
  25. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +13 -144
  26. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.swift +81 -0
  27. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +13 -143
  28. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.swift +81 -0
  29. package/ios_config.sh +10 -0
  30. package/lib/commonjs/ads/MobileAd.js +1 -1
  31. package/lib/commonjs/ads/MobileAd.js.map +1 -1
  32. package/lib/commonjs/validateAdRequestOptions.js +8 -0
  33. package/lib/commonjs/validateAdRequestOptions.js.map +1 -1
  34. package/lib/commonjs/version.js +1 -1
  35. package/lib/commonjs/version.js.map +1 -1
  36. package/lib/module/ads/MobileAd.js +1 -1
  37. package/lib/module/ads/MobileAd.js.map +1 -1
  38. package/lib/module/validateAdRequestOptions.js +8 -0
  39. package/lib/module/validateAdRequestOptions.js.map +1 -1
  40. package/lib/module/version.js +1 -1
  41. package/lib/module/version.js.map +1 -1
  42. package/lib/typescript/index.d.ts +1 -1
  43. package/lib/typescript/types/RequestOptions.d.ts +6 -0
  44. package/lib/typescript/version.d.ts +1 -1
  45. package/package.json +4 -4
  46. package/src/ads/MobileAd.ts +2 -1
  47. package/src/types/RequestOptions.ts +7 -0
  48. package/src/validateAdRequestOptions.ts +7 -0
  49. package/src/version.ts +1 -1
  50. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +0 -159
  51. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +0 -178
  52. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.java +0 -199
  53. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.java +0 -176
  54. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.h +0 -29
  55. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +0 -33
  56. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +0 -72
  57. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.h +0 -25
  58. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.h +0 -25
  59. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.h +0 -25
@@ -1,176 +0,0 @@
1
- package io.invertase.googlemobileads;
2
-
3
- import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsCommon.buildAdRequest;
4
- import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsCommon.getCodeAndMessageFromAdError;
5
- import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsCommon.sendAdEvent;
6
- import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLOSED;
7
- import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_ERROR;
8
- import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_OPENED;
9
- import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD;
10
- import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED;
11
-
12
- import android.app.Activity;
13
- import android.util.SparseArray;
14
- import androidx.annotation.NonNull;
15
- import androidx.annotation.Nullable;
16
- import com.facebook.react.bridge.Arguments;
17
- import com.facebook.react.bridge.Promise;
18
- import com.facebook.react.bridge.ReactApplicationContext;
19
- import com.facebook.react.bridge.ReactMethod;
20
- import com.facebook.react.bridge.ReadableMap;
21
- import com.facebook.react.bridge.WritableMap;
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.rewarded.RewardItem;
26
- import com.google.android.gms.ads.rewarded.RewardedAd;
27
- import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
28
- import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions;
29
- import io.invertase.googlemobileads.common.ReactNativeModule;
30
-
31
- public class ReactNativeGoogleMobileAdsRewardedModule extends ReactNativeModule {
32
- private static final String SERVICE = "RNGoogleMobileAdsRewardedModule";
33
- private static SparseArray<RewardedAd> rewardedAdArray = new SparseArray<>();
34
-
35
- public ReactNativeGoogleMobileAdsRewardedModule(ReactApplicationContext reactContext) {
36
- super(reactContext, SERVICE);
37
- }
38
-
39
- private void sendRewardedEvent(
40
- String type,
41
- int requestId,
42
- String adUnitId,
43
- @Nullable WritableMap error,
44
- @Nullable WritableMap data) {
45
- sendAdEvent(
46
- ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED,
47
- requestId,
48
- type,
49
- adUnitId,
50
- error,
51
- data);
52
- }
53
-
54
- @ReactMethod
55
- public void rewardedLoad(int requestId, String adUnitId, ReadableMap adRequestOptions) {
56
- Activity activity = getCurrentActivity();
57
- if (activity == null) {
58
- WritableMap error = Arguments.createMap();
59
- error.putString("code", "null-activity");
60
- error.putString(
61
- "message", "Rewarded ad attempted to load but the current Activity was null.");
62
- sendRewardedEvent(GOOGLE_MOBILE_ADS_EVENT_ERROR, requestId, adUnitId, error, null);
63
- return;
64
- }
65
- activity.runOnUiThread(
66
- () -> {
67
- RewardedAdLoadCallback rewardedAdLoadCallback =
68
- new RewardedAdLoadCallback() {
69
- @Override
70
- public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
71
- WritableMap error = Arguments.createMap();
72
- String[] codeAndMessage = getCodeAndMessageFromAdError(loadAdError);
73
- error.putString("code", codeAndMessage[0]);
74
- error.putString("message", codeAndMessage[1]);
75
- sendRewardedEvent(
76
- GOOGLE_MOBILE_ADS_EVENT_ERROR, requestId, adUnitId, error, null);
77
- }
78
-
79
- @Override
80
- public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
81
- RewardItem rewardItem = rewardedAd.getRewardItem();
82
- WritableMap data = Arguments.createMap();
83
- data.putString("type", rewardItem.getType());
84
- data.putInt("amount", rewardItem.getAmount());
85
-
86
- if (adRequestOptions.hasKey("serverSideVerificationOptions")) {
87
- ReadableMap serverSideVerificationOptions =
88
- adRequestOptions.getMap("serverSideVerificationOptions");
89
-
90
- if (serverSideVerificationOptions != null) {
91
- ServerSideVerificationOptions.Builder options =
92
- new ServerSideVerificationOptions.Builder();
93
-
94
- if (serverSideVerificationOptions.hasKey("userId")) {
95
- options.setUserId(serverSideVerificationOptions.getString("userId"));
96
- }
97
-
98
- if (serverSideVerificationOptions.hasKey("customData")) {
99
- options.setCustomData(
100
- serverSideVerificationOptions.getString("customData"));
101
- }
102
-
103
- rewardedAd.setServerSideVerificationOptions(options.build());
104
- }
105
- }
106
-
107
- FullScreenContentCallback fullScreenContentCallback =
108
- new FullScreenContentCallback() {
109
- @Override
110
- public void onAdShowedFullScreenContent() {
111
- sendRewardedEvent(
112
- GOOGLE_MOBILE_ADS_EVENT_OPENED, requestId, adUnitId, null, null);
113
- }
114
-
115
- @Override
116
- public void onAdDismissedFullScreenContent() {
117
- sendRewardedEvent(
118
- GOOGLE_MOBILE_ADS_EVENT_CLOSED, requestId, adUnitId, null, null);
119
- }
120
- };
121
-
122
- rewardedAd.setFullScreenContentCallback(fullScreenContentCallback);
123
-
124
- rewardedAdArray.put(requestId, rewardedAd);
125
- sendRewardedEvent(
126
- GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED, requestId, adUnitId, null, data);
127
- }
128
- };
129
-
130
- RewardedAd.load(
131
- activity, adUnitId, buildAdRequest(adRequestOptions), rewardedAdLoadCallback);
132
- });
133
- }
134
-
135
- @ReactMethod
136
- public void rewardedShow(
137
- int requestId, String adUnitId, ReadableMap showOptions, Promise promise) {
138
- if (getCurrentActivity() == null) {
139
- rejectPromiseWithCodeAndMessage(
140
- promise,
141
- "null-activity",
142
- "Rewarded ad attempted to show but the current Activity was null.");
143
- return;
144
- }
145
- getCurrentActivity()
146
- .runOnUiThread(
147
- () -> {
148
- RewardedAd rewardedAd = rewardedAdArray.get(requestId);
149
-
150
- boolean immersiveModeEnabled = false;
151
- if (showOptions.hasKey("immersiveModeEnabled")) {
152
- immersiveModeEnabled = showOptions.getBoolean("immersiveModeEnabled");
153
- }
154
- rewardedAd.setImmersiveMode(immersiveModeEnabled);
155
-
156
- OnUserEarnedRewardListener onUserEarnedRewardListener =
157
- new OnUserEarnedRewardListener() {
158
- @Override
159
- public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
160
- WritableMap data = Arguments.createMap();
161
- data.putString("type", rewardItem.getType());
162
- data.putInt("amount", rewardItem.getAmount());
163
- sendRewardedEvent(
164
- GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD,
165
- requestId,
166
- adUnitId,
167
- null,
168
- data);
169
- }
170
- };
171
-
172
- rewardedAd.show(getCurrentActivity(), onUserEarnedRewardListener);
173
- promise.resolve(null);
174
- });
175
- }
176
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import <Foundation/Foundation.h>
19
- #import <React/RCTBridgeModule.h>
20
- #import "RNGoogleMobileAdsFullScreenContentDelegate.h"
21
-
22
- @import GoogleMobileAds;
23
-
24
- @interface RNGoogleMobileAdsAppOpenModule : NSObject <RCTBridgeModule>
25
-
26
- @property(strong, nonatomic) GADAppOpenAd* appOpenAd;
27
- @property(strong, nonatomic) RNGoogleMobileAdsFullScreenContentDelegate* appOpenDelegate;
28
-
29
- @end
@@ -1,33 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import <Foundation/Foundation.h>
19
-
20
- #import <React/RCTBridgeModule.h>
21
-
22
- @import GoogleMobileAds;
23
-
24
- #import "RNGoogleMobileAdsCommon.h"
25
-
26
- @interface RNGoogleMobileAdsFullScreenContentDelegate
27
- : NSObject <GADFullScreenContentDelegate, GADAppEventDelegate>
28
-
29
- @property(nonatomic, copy) NSString *sendAdEvent;
30
- @property(nonatomic, copy) NSNumber *requestId;
31
- @property(nonatomic, copy) NSString *adUnitId;
32
-
33
- @end
@@ -1,72 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present Invertase Limited & Contributors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this library except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- #import "RNGoogleMobileAdsFullScreenContentDelegate.h"
19
-
20
- @implementation RNGoogleMobileAdsFullScreenContentDelegate
21
-
22
- #pragma mark -
23
- #pragma mark GADFullScreenContentDelegate Methods
24
-
25
- /// Tells the delegate that the ad is about to present full screen content.
26
- - (void)adWillPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
27
- [RNGoogleMobileAdsCommon sendAdEvent:_sendAdEvent
28
- requestId:_requestId
29
- type:GOOGLE_MOBILE_ADS_EVENT_OPENED
30
- adUnitId:_adUnitId
31
- error:nil
32
- data:nil];
33
- }
34
-
35
- /// Tells the delegate that the ad failed to present full screen content.
36
- - (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
37
- didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
38
- NSDictionary *codeAndMessage = [RNGoogleMobileAdsCommon getCodeAndMessageFromAdError:error];
39
- [RNGoogleMobileAdsCommon sendAdEvent:_sendAdEvent
40
- requestId:_requestId
41
- type:GOOGLE_MOBILE_ADS_EVENT_ERROR
42
- adUnitId:_adUnitId
43
- error:codeAndMessage
44
- data:nil];
45
- }
46
-
47
- /// Tells the delegate that the ad dismissed full screen content.
48
- - (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
49
- [RNGoogleMobileAdsCommon sendAdEvent:_sendAdEvent
50
- requestId:_requestId
51
- type:GOOGLE_MOBILE_ADS_EVENT_CLOSED
52
- adUnitId:_adUnitId
53
- error:nil
54
- data:nil];
55
- }
56
-
57
- /// Called when the ad receives an app event.
58
- - (void)ad:(nonnull GADInterstitialAd *)ad
59
- didReceiveAppEvent:(nonnull NSString *)name
60
- withInfo:(nullable NSString *)info {
61
- [RNGoogleMobileAdsCommon sendAdEvent:_sendAdEvent
62
- requestId:_requestId
63
- type:GOOGLE_MOBILE_ADS_EVENT_APP_EVENT
64
- adUnitId:_adUnitId
65
- error:nil
66
- data:@{
67
- @"name" : name,
68
- @"data" : info,
69
- }];
70
- }
71
-
72
- @end
@@ -1,25 +0,0 @@
1
- //
2
- /**
3
- * Copyright (c) 2016-present Invertase Limited & Contributors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this library except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
- #import <Foundation/Foundation.h>
20
-
21
- #import <React/RCTBridgeModule.h>
22
-
23
- @interface RNGoogleMobileAdsInterstitialModule : NSObject <RCTBridgeModule>
24
-
25
- @end
@@ -1,25 +0,0 @@
1
- //
2
- /**
3
- * Copyright (c) 2016-present Invertase Limited & Contributors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this library except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
- #import <Foundation/Foundation.h>
20
-
21
- #import <React/RCTBridgeModule.h>
22
-
23
- @interface RNGoogleMobileAdsRewardedInterstitialModule : NSObject <RCTBridgeModule>
24
-
25
- @end
@@ -1,25 +0,0 @@
1
- //
2
- /**
3
- * Copyright (c) 2016-present Invertase Limited & Contributors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this library except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
- #import <Foundation/Foundation.h>
20
-
21
- #import <React/RCTBridgeModule.h>
22
-
23
- @interface RNGoogleMobileAdsRewardedModule : NSObject <RCTBridgeModule>
24
-
25
- @end