react-native-google-mobile-ads 6.0.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java +2 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java +1 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.java +199 -0
- package/docs/displaying-ads-hook.mdx +1 -1
- package/docs/displaying-ads.mdx +132 -1
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +1 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +2 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +173 -0
- package/lib/commonjs/MobileAds.js +5 -2
- package/lib/commonjs/MobileAds.js.map +1 -1
- package/lib/commonjs/TestIds.js +6 -2
- package/lib/commonjs/TestIds.js.map +1 -1
- package/lib/commonjs/ads/MobileAd.js +16 -4
- package/lib/commonjs/ads/MobileAd.js.map +1 -1
- package/lib/commonjs/ads/RewardedInterstitialAd.js +127 -0
- package/lib/commonjs/ads/RewardedInterstitialAd.js.map +1 -0
- package/lib/commonjs/hooks/useFullScreenAd.js.map +1 -1
- package/lib/commonjs/hooks/useRewardedAd.js.map +1 -1
- package/lib/commonjs/hooks/useRewardedInterstitialAd.js +51 -0
- package/lib/commonjs/hooks/useRewardedInterstitialAd.js.map +1 -0
- package/lib/commonjs/index.js +19 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/MobileAds.js +5 -2
- package/lib/module/MobileAds.js.map +1 -1
- package/lib/module/TestIds.js +6 -2
- package/lib/module/TestIds.js.map +1 -1
- package/lib/module/ads/MobileAd.js +16 -4
- package/lib/module/ads/MobileAd.js.map +1 -1
- package/lib/module/ads/RewardedInterstitialAd.js +130 -0
- package/lib/module/ads/RewardedInterstitialAd.js.map +1 -0
- package/lib/module/hooks/useFullScreenAd.js.map +1 -1
- package/lib/module/hooks/useRewardedAd.js.map +1 -1
- package/lib/module/hooks/useRewardedInterstitialAd.js +38 -0
- package/lib/module/hooks/useRewardedInterstitialAd.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/TestIds.d.ts +2 -0
- package/lib/typescript/ads/MobileAd.d.ts +3 -2
- package/lib/typescript/ads/RewardedInterstitialAd.d.ts +82 -0
- package/lib/typescript/hooks/useFullScreenAd.d.ts +2 -1
- package/lib/typescript/hooks/useRewardedAd.d.ts +1 -1
- package/lib/typescript/hooks/useRewardedInterstitialAd.d.ts +9 -0
- package/lib/typescript/index.d.ts +3 -1
- package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +11 -6
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/MobileAds.ts +9 -0
- package/src/TestIds.ts +4 -0
- package/src/ads/MobileAd.ts +16 -6
- package/src/ads/RewardedInterstitialAd.ts +143 -0
- package/src/hooks/useFullScreenAd.ts +4 -3
- package/src/hooks/useRewardedAd.ts +1 -1
- package/src/hooks/useRewardedInterstitialAd.ts +47 -0
- package/src/index.ts +2 -0
- package/src/types/GoogleMobileAdsNativeModule.ts +15 -6
- package/src/version.ts +1 -1
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java
CHANGED
|
@@ -26,6 +26,8 @@ public class ReactNativeGoogleMobileAdsEvent implements NativeEvent {
|
|
|
26
26
|
public static final String GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL =
|
|
27
27
|
"google_mobile_ads_interstitial_event";
|
|
28
28
|
public static final String GOOGLE_MOBILE_ADS_EVENT_REWARDED = "google_mobile_ads_rewarded_event";
|
|
29
|
+
public static final String GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL =
|
|
30
|
+
"google_mobile_ads_rewarded_interstitial_event";
|
|
29
31
|
|
|
30
32
|
public static final String GOOGLE_MOBILE_ADS_EVENT_LOADED = "loaded";
|
|
31
33
|
public static final String GOOGLE_MOBILE_ADS_EVENT_ERROR = "error";
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java
CHANGED
|
@@ -37,6 +37,7 @@ public class ReactNativeGoogleMobileAdsPackage implements ReactPackage {
|
|
|
37
37
|
modules.add(new ReactNativeGoogleMobileAdsAppOpenModule(reactContext));
|
|
38
38
|
modules.add(new ReactNativeGoogleMobileAdsInterstitialModule(reactContext));
|
|
39
39
|
modules.add(new ReactNativeGoogleMobileAdsRewardedModule(reactContext));
|
|
40
|
+
modules.add(new ReactNativeGoogleMobileAdsRewardedInterstitialModule(reactContext));
|
|
40
41
|
return modules;
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -0,0 +1,199 @@
|
|
|
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 static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsCommon.buildAdRequest;
|
|
21
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsCommon.getCodeAndMessageFromAdError;
|
|
22
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsCommon.sendAdEvent;
|
|
23
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLOSED;
|
|
24
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_ERROR;
|
|
25
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_OPENED;
|
|
26
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD;
|
|
27
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED;
|
|
28
|
+
|
|
29
|
+
import android.app.Activity;
|
|
30
|
+
import android.util.SparseArray;
|
|
31
|
+
import androidx.annotation.NonNull;
|
|
32
|
+
import androidx.annotation.Nullable;
|
|
33
|
+
import com.facebook.react.bridge.Arguments;
|
|
34
|
+
import com.facebook.react.bridge.Promise;
|
|
35
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
36
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
37
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
38
|
+
import com.facebook.react.bridge.WritableMap;
|
|
39
|
+
import com.google.android.gms.ads.FullScreenContentCallback;
|
|
40
|
+
import com.google.android.gms.ads.LoadAdError;
|
|
41
|
+
import com.google.android.gms.ads.OnUserEarnedRewardListener;
|
|
42
|
+
import com.google.android.gms.ads.rewarded.RewardItem;
|
|
43
|
+
import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions;
|
|
44
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;
|
|
45
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;
|
|
46
|
+
import io.invertase.googlemobileads.common.ReactNativeModule;
|
|
47
|
+
|
|
48
|
+
public class ReactNativeGoogleMobileAdsRewardedInterstitialModule extends ReactNativeModule {
|
|
49
|
+
private static final String SERVICE = "RNGoogleMobileAdsRewardedInterstitialModule";
|
|
50
|
+
private static SparseArray<RewardedInterstitialAd> rewardedInterstitialAdArray =
|
|
51
|
+
new SparseArray<>();
|
|
52
|
+
|
|
53
|
+
public ReactNativeGoogleMobileAdsRewardedInterstitialModule(
|
|
54
|
+
ReactApplicationContext reactContext) {
|
|
55
|
+
super(reactContext, SERVICE);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private void sendRewardedInterstitialEvent(
|
|
59
|
+
String type,
|
|
60
|
+
int requestId,
|
|
61
|
+
String adUnitId,
|
|
62
|
+
@Nullable WritableMap error,
|
|
63
|
+
@Nullable WritableMap data) {
|
|
64
|
+
sendAdEvent(
|
|
65
|
+
ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL,
|
|
66
|
+
requestId,
|
|
67
|
+
type,
|
|
68
|
+
adUnitId,
|
|
69
|
+
error,
|
|
70
|
+
data);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@ReactMethod
|
|
74
|
+
public void rewardedInterstitialLoad(
|
|
75
|
+
int requestId, String adUnitId, ReadableMap adRequestOptions) {
|
|
76
|
+
Activity activity = getCurrentActivity();
|
|
77
|
+
if (activity == null) {
|
|
78
|
+
WritableMap error = Arguments.createMap();
|
|
79
|
+
error.putString("code", "null-activity");
|
|
80
|
+
error.putString(
|
|
81
|
+
"message",
|
|
82
|
+
"Rewarded Interstitial ad attempted to load but the current Activity was null.");
|
|
83
|
+
sendRewardedInterstitialEvent(
|
|
84
|
+
GOOGLE_MOBILE_ADS_EVENT_ERROR, requestId, adUnitId, error, null);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
activity.runOnUiThread(
|
|
88
|
+
() -> {
|
|
89
|
+
RewardedInterstitialAdLoadCallback rewardedAdLoadCallback =
|
|
90
|
+
new RewardedInterstitialAdLoadCallback() {
|
|
91
|
+
@Override
|
|
92
|
+
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
|
|
93
|
+
WritableMap error = Arguments.createMap();
|
|
94
|
+
String[] codeAndMessage = getCodeAndMessageFromAdError(loadAdError);
|
|
95
|
+
error.putString("code", codeAndMessage[0]);
|
|
96
|
+
error.putString("message", codeAndMessage[1]);
|
|
97
|
+
sendRewardedInterstitialEvent(
|
|
98
|
+
GOOGLE_MOBILE_ADS_EVENT_ERROR, requestId, adUnitId, error, null);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Override
|
|
102
|
+
public void onAdLoaded(@NonNull RewardedInterstitialAd rewardedInterstitialAd) {
|
|
103
|
+
RewardItem rewardItem = rewardedInterstitialAd.getRewardItem();
|
|
104
|
+
WritableMap data = Arguments.createMap();
|
|
105
|
+
data.putString("type", rewardItem.getType());
|
|
106
|
+
data.putInt("amount", rewardItem.getAmount());
|
|
107
|
+
|
|
108
|
+
if (adRequestOptions.hasKey("serverSideVerificationOptions")) {
|
|
109
|
+
ReadableMap serverSideVerificationOptions =
|
|
110
|
+
adRequestOptions.getMap("serverSideVerificationOptions");
|
|
111
|
+
|
|
112
|
+
if (serverSideVerificationOptions != null) {
|
|
113
|
+
ServerSideVerificationOptions.Builder options =
|
|
114
|
+
new ServerSideVerificationOptions.Builder();
|
|
115
|
+
|
|
116
|
+
if (serverSideVerificationOptions.hasKey("userId")) {
|
|
117
|
+
options.setUserId(serverSideVerificationOptions.getString("userId"));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (serverSideVerificationOptions.hasKey("customData")) {
|
|
121
|
+
options.setCustomData(
|
|
122
|
+
serverSideVerificationOptions.getString("customData"));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
rewardedInterstitialAd.setServerSideVerificationOptions(options.build());
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
FullScreenContentCallback fullScreenContentCallback =
|
|
130
|
+
new FullScreenContentCallback() {
|
|
131
|
+
@Override
|
|
132
|
+
public void onAdShowedFullScreenContent() {
|
|
133
|
+
sendRewardedInterstitialEvent(
|
|
134
|
+
GOOGLE_MOBILE_ADS_EVENT_OPENED, requestId, adUnitId, null, null);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@Override
|
|
138
|
+
public void onAdDismissedFullScreenContent() {
|
|
139
|
+
sendRewardedInterstitialEvent(
|
|
140
|
+
GOOGLE_MOBILE_ADS_EVENT_CLOSED, requestId, adUnitId, null, null);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
rewardedInterstitialAd.setFullScreenContentCallback(fullScreenContentCallback);
|
|
145
|
+
|
|
146
|
+
rewardedInterstitialAdArray.put(requestId, rewardedInterstitialAd);
|
|
147
|
+
sendRewardedInterstitialEvent(
|
|
148
|
+
GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED, requestId, adUnitId, null, data);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
RewardedInterstitialAd.load(
|
|
153
|
+
activity, adUnitId, buildAdRequest(adRequestOptions), rewardedAdLoadCallback);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@ReactMethod
|
|
158
|
+
public void rewardedInterstitialShow(
|
|
159
|
+
int requestId, String adUnitId, ReadableMap showOptions, Promise promise) {
|
|
160
|
+
if (getCurrentActivity() == null) {
|
|
161
|
+
rejectPromiseWithCodeAndMessage(
|
|
162
|
+
promise,
|
|
163
|
+
"null-activity",
|
|
164
|
+
"Rewarded Interstitial ad attempted to show but the current Activity was null.");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
getCurrentActivity()
|
|
168
|
+
.runOnUiThread(
|
|
169
|
+
() -> {
|
|
170
|
+
RewardedInterstitialAd rewardedInterstitialAd =
|
|
171
|
+
rewardedInterstitialAdArray.get(requestId);
|
|
172
|
+
|
|
173
|
+
boolean immersiveModeEnabled = false;
|
|
174
|
+
if (showOptions.hasKey("immersiveModeEnabled")) {
|
|
175
|
+
immersiveModeEnabled = showOptions.getBoolean("immersiveModeEnabled");
|
|
176
|
+
}
|
|
177
|
+
rewardedInterstitialAd.setImmersiveMode(immersiveModeEnabled);
|
|
178
|
+
|
|
179
|
+
OnUserEarnedRewardListener onUserEarnedRewardListener =
|
|
180
|
+
new OnUserEarnedRewardListener() {
|
|
181
|
+
@Override
|
|
182
|
+
public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
|
|
183
|
+
WritableMap data = Arguments.createMap();
|
|
184
|
+
data.putString("type", rewardItem.getType());
|
|
185
|
+
data.putInt("amount", rewardItem.getAmount());
|
|
186
|
+
sendRewardedInterstitialEvent(
|
|
187
|
+
GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD,
|
|
188
|
+
requestId,
|
|
189
|
+
adUnitId,
|
|
190
|
+
null,
|
|
191
|
+
data);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
rewardedInterstitialAd.show(getCurrentActivity(), onUserEarnedRewardListener);
|
|
196
|
+
promise.resolve(null);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Hooks
|
|
2
2
|
|
|
3
|
-
The AdMob package provides hooks to help you to display ads in a functional component with tiny code. The supported ad formats are full-screen ads: App open, Interstitial
|
|
3
|
+
The AdMob package provides hooks to help you to display ads in a functional component with tiny code. The supported ad formats are full-screen ads: App open, Interstitial, Rewarded, and Rewarded Interstitial.
|
|
4
4
|
|
|
5
5
|
## Load an ad
|
|
6
6
|
|
package/docs/displaying-ads.mdx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Displaying Ads
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The Google Mobile Ads package allows you to display five types of adverts; App Open, Interstitial, Rewarded, Rewarded Interstitial, and Banner.
|
|
4
4
|
|
|
5
5
|
## App Open Ads
|
|
6
6
|
|
|
@@ -265,6 +265,137 @@ If you request an Advert as in the example above, AdMob will call your server wi
|
|
|
265
265
|
|
|
266
266
|
You still need to verify these incoming requests yourself to ensure they are genuine. To learn more about callback parameters and verifying, see the [AdMob SDK Server Side Verification(SSV) documentation](https://developers.google.com/admob/android/rewarded-video-ssv).
|
|
267
267
|
|
|
268
|
+
## Rewarded Interstitial Ads
|
|
269
|
+
|
|
270
|
+
Rewarded Interstitial Ads are full-screen ads that cover the interface of an app until closed by the user. The content of a rewarded interstitial
|
|
271
|
+
advert is controlled via the Google AdMob dashboard.
|
|
272
|
+
|
|
273
|
+
The purpose of a rewarded interstitial ad is to reward users with _something_ after completing an action inside of the advert, such
|
|
274
|
+
as watching a video or submitting an option via an interactive form. If the user completes the action, you can reward them
|
|
275
|
+
with something (e.g. in-game currency). Unlike rewarded ads, users aren't required to opt-in to view a rewarded interstitial.
|
|
276
|
+
|
|
277
|
+
To create a new rewarded interstitial ad, call the `createForAdRequest` method from the `RewardedInterstitialAd` class. The first argument
|
|
278
|
+
of the method is the "Ad Unit ID". For testing, we can use a Test ID, however for production the ID from the
|
|
279
|
+
Google AdMob dashboard under "Ad units" should be used:
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
import { RewardedInterstitialAd, TestIds } from 'react-native-google-mobile-ads';
|
|
283
|
+
|
|
284
|
+
const adUnitId = __DEV__
|
|
285
|
+
? TestIds.REWARDED_INTERSTITIAL
|
|
286
|
+
: 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
|
|
287
|
+
|
|
288
|
+
const rewardedInterstitial = RewardedInterstitialAd.createForAdRequest(adUnitId, {
|
|
289
|
+
requestNonPersonalizedAdsOnly: true,
|
|
290
|
+
keywords: ['fashion', 'clothing'],
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
The second argument is additional optional request options object to be sent whilst loading an advert, such as keywords & location.
|
|
295
|
+
Setting additional request options helps AdMob choose better tailored ads from the network. View the [`RequestOptions`](/reference/admob/requestoptions)
|
|
296
|
+
documentation to view the full range of options available.
|
|
297
|
+
|
|
298
|
+
The call to `createForAdRequest` returns an instance of the [`RewardedInterstitialAd`](/reference/admob/rewardedinterstitialad) class,
|
|
299
|
+
which provides a number of utilities for loading and displaying rewarded interstitial ads.
|
|
300
|
+
|
|
301
|
+
To listen to events, such as when the advert from the network has loaded or when an error occurs, we can subscribe via the
|
|
302
|
+
`addAdEventListener` method:
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
import React, { useEffect, useState } from 'react';
|
|
306
|
+
import { Button } from 'react-native';
|
|
307
|
+
import {
|
|
308
|
+
RewardedInterstitialAd,
|
|
309
|
+
RewardedAdEventType,
|
|
310
|
+
TestIds,
|
|
311
|
+
} from 'react-native-google-mobile-ads';
|
|
312
|
+
|
|
313
|
+
const adUnitId = __DEV__
|
|
314
|
+
? TestIds.REWARDED_INTERSTITIAL
|
|
315
|
+
: 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
|
|
316
|
+
|
|
317
|
+
const rewardedInterstitial = RewardedInterstitialAd.createForAdRequest(adUnitId, {
|
|
318
|
+
requestNonPersonalizedAdsOnly: true,
|
|
319
|
+
keywords: ['fashion', 'clothing'],
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
function App() {
|
|
323
|
+
const [loaded, setLoaded] = useState(false);
|
|
324
|
+
|
|
325
|
+
useEffect(() => {
|
|
326
|
+
const unsubscribeLoaded = rewardedInterstitial.addAdEventListener(
|
|
327
|
+
RewardedAdEventType.LOADED,
|
|
328
|
+
() => {
|
|
329
|
+
setLoaded(true);
|
|
330
|
+
},
|
|
331
|
+
);
|
|
332
|
+
const unsubscribeEarned = rewardedInterstitial.addAdEventListener(
|
|
333
|
+
RewardedAdEventType.EARNED_REWARD,
|
|
334
|
+
reward => {
|
|
335
|
+
console.log('User earned reward of ', reward);
|
|
336
|
+
},
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
// Start loading the rewarded interstitial ad straight away
|
|
340
|
+
rewardedInterstitial.load();
|
|
341
|
+
|
|
342
|
+
// Unsubscribe from events on unmount
|
|
343
|
+
return () => {
|
|
344
|
+
unsubscribeLoaded();
|
|
345
|
+
unsubscribeEarned();
|
|
346
|
+
};
|
|
347
|
+
}, []);
|
|
348
|
+
|
|
349
|
+
// No advert ready to show yet
|
|
350
|
+
if (!loaded) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return (
|
|
355
|
+
<Button
|
|
356
|
+
title="Show Rewarded Interstitial Ad"
|
|
357
|
+
onPress={() => {
|
|
358
|
+
rewardedInterstitial.show();
|
|
359
|
+
}}
|
|
360
|
+
/>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
The code above subscribes to the rewarded interstitial ad events (via `addAdEventListener()`) and immediately starts to load a new advert from
|
|
366
|
+
the network (via `load()`). Once an advert is available, local state is set, re-rendering the component showing a `Button`.
|
|
367
|
+
When pressed, the `show` method on the rewarded interstitial ad instance is called and the advert is shown over-the-top of your
|
|
368
|
+
application.
|
|
369
|
+
|
|
370
|
+
Like Interstitial Ads, you can listen to the events with the `addAdEventListener` such as when the user clicks the advert or closes
|
|
371
|
+
the advert and returns back to your app. However, you can listen to an extra `EARNED_REWARD` event which is triggered when user completes the
|
|
372
|
+
advert action. An additional `reward` payload is sent with the event, containing the amount and type of rewarded (specified via the dashboard).
|
|
373
|
+
|
|
374
|
+
To learn more, view the [`RewardedAdEventType`](/reference/admob/rewardedadeventtype) documentation.
|
|
375
|
+
|
|
376
|
+
If needed, you can reuse the existing instance of the `RewardedInterstitialAd` class to load more adverts and show them when required.
|
|
377
|
+
|
|
378
|
+
While the `EARNED_REWARD` event only occurs on the client, Server Side Verification (or SSV) can be used for confirming a user completed an advert action. For this, you have to specify the Server Side Verification callback URL in your Ads dashboard.
|
|
379
|
+
|
|
380
|
+
You can customize SSV parameters when your SSV callback is called by setting the `serverSideVerificationOptions` field in your [`RequestOptions`](/reference/admob/requestoptions) parameter.
|
|
381
|
+
|
|
382
|
+
```js
|
|
383
|
+
const rewardedInterstitialAd = RewardedInterstitialAd.createForAdRequest(adUnitId, {
|
|
384
|
+
serverSideVerificationOptions: {
|
|
385
|
+
userId: '9999',
|
|
386
|
+
customData: 'my-custom-data',
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
If you request an Advert as in the example above, AdMob will call your server with the `userId` and `customData` fields as shown below:
|
|
392
|
+
|
|
393
|
+
```
|
|
394
|
+
[14/Aug/2020 12:51:43] "GET /views/admob-ssv/?ad_network=...&ad_unit=...&custom_data=my-custom-data&reward_amount=1&reward_item=test_reward_item×tamp=1597377102267&transaction_id=148cc85...&user_id=9999&signature=MEUCIQCQSi3cQ2PlxlEAkpN...&key_id=3335... HTTP/1.1" 200 0
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
You still need to verify these incoming requests yourself to ensure they are genuine. To learn more about callback parameters and verifying, see the [AdMob SDK Server Side Verification(SSV) documentation](https://developers.google.com/admob/android/rewarded-video-ssv).
|
|
398
|
+
|
|
268
399
|
## Banner Ads
|
|
269
400
|
|
|
270
401
|
Banner ads are partial adverts which can be integrated within your existing application. Unlike Interstitial and Rewarded Ads,
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
extern NSString *const GOOGLE_MOBILE_ADS_EVENT_APP_OPEN;
|
|
52
52
|
extern NSString *const GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL;
|
|
53
53
|
extern NSString *const GOOGLE_MOBILE_ADS_EVENT_REWARDED;
|
|
54
|
+
extern NSString *const GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL;
|
|
54
55
|
|
|
55
56
|
extern NSString *const GOOGLE_MOBILE_ADS_EVENT_LOADED;
|
|
56
57
|
extern NSString *const GOOGLE_MOBILE_ADS_EVENT_ERROR;
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
NSString *const GOOGLE_MOBILE_ADS_EVENT_APP_OPEN = @"google_mobile_ads_app_open_event";
|
|
23
23
|
NSString *const GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL = @"google_mobile_ads_interstitial_event";
|
|
24
24
|
NSString *const GOOGLE_MOBILE_ADS_EVENT_REWARDED = @"google_mobile_ads_rewarded_event";
|
|
25
|
+
NSString *const GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL =
|
|
26
|
+
@"google_mobile_ads_rewarded_interstitial_event";
|
|
25
27
|
NSString *const GOOGLE_MOBILE_ADS_EVENT_LOADED = @"loaded";
|
|
26
28
|
NSString *const GOOGLE_MOBILE_ADS_EVENT_ERROR = @"error";
|
|
27
29
|
NSString *const GOOGLE_MOBILE_ADS_EVENT_OPENED = @"opened";
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
@@ -0,0 +1,173 @@
|
|
|
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 <React/RCTUtils.h>
|
|
20
|
+
|
|
21
|
+
#import "RNGoogleMobileAdsCommon.h"
|
|
22
|
+
#import "RNGoogleMobileAdsFullScreenContentDelegate.h"
|
|
23
|
+
#import "RNGoogleMobileAdsRewardedInterstitialModule.h"
|
|
24
|
+
#import "common/RNSharedUtils.h"
|
|
25
|
+
|
|
26
|
+
static __strong NSMutableDictionary *rewardedInterstitialMap;
|
|
27
|
+
static __strong NSMutableDictionary *rewardedInterstitialDelegateMap;
|
|
28
|
+
|
|
29
|
+
@implementation RNGoogleMobileAdsRewardedInterstitialModule
|
|
30
|
+
#pragma mark -
|
|
31
|
+
#pragma mark Module Setup
|
|
32
|
+
|
|
33
|
+
RCT_EXPORT_MODULE();
|
|
34
|
+
|
|
35
|
+
- (dispatch_queue_t)methodQueue {
|
|
36
|
+
return dispatch_get_main_queue();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (id)init {
|
|
40
|
+
self = [super init];
|
|
41
|
+
static dispatch_once_t onceToken;
|
|
42
|
+
dispatch_once(&onceToken, ^{
|
|
43
|
+
rewardedInterstitialMap = [[NSMutableDictionary alloc] init];
|
|
44
|
+
rewardedInterstitialDelegateMap = [[NSMutableDictionary alloc] init];
|
|
45
|
+
});
|
|
46
|
+
return self;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
50
|
+
return YES;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)dealloc {
|
|
54
|
+
[self invalidate];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
- (void)invalidate {
|
|
58
|
+
for (NSNumber *id in [rewardedInterstitialMap allKeys]) {
|
|
59
|
+
[rewardedInterstitialMap removeObjectForKey:id];
|
|
60
|
+
[rewardedInterstitialDelegateMap removeObjectForKey:id];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#pragma mark -
|
|
65
|
+
#pragma mark Google Mobile Ads Methods
|
|
66
|
+
|
|
67
|
+
RCT_EXPORT_METHOD(rewardedInterstitialLoad
|
|
68
|
+
: (nonnull NSNumber *)requestId
|
|
69
|
+
: (NSString *)adUnitId
|
|
70
|
+
: (NSDictionary *)adRequestOptions) {
|
|
71
|
+
[GADRewardedInterstitialAd
|
|
72
|
+
loadWithAdUnitID:adUnitId
|
|
73
|
+
request:[RNGoogleMobileAdsCommon buildAdRequest:adRequestOptions]
|
|
74
|
+
completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
|
|
75
|
+
if (error) {
|
|
76
|
+
NSDictionary *codeAndMessage =
|
|
77
|
+
[RNGoogleMobileAdsCommon getCodeAndMessageFromAdError:error];
|
|
78
|
+
[RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
|
|
79
|
+
requestId:requestId
|
|
80
|
+
type:GOOGLE_MOBILE_ADS_EVENT_ERROR
|
|
81
|
+
adUnitId:adUnitId
|
|
82
|
+
error:codeAndMessage
|
|
83
|
+
data:nil];
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
GADRewardedInterstitialAd *rewardedInterstitialAd = ad;
|
|
87
|
+
|
|
88
|
+
NSDictionary *serverSideVerificationOptions =
|
|
89
|
+
[adRequestOptions objectForKey:@"serverSideVerificationOptions"];
|
|
90
|
+
|
|
91
|
+
if (serverSideVerificationOptions != nil) {
|
|
92
|
+
GADServerSideVerificationOptions *options =
|
|
93
|
+
[[GADServerSideVerificationOptions alloc] init];
|
|
94
|
+
|
|
95
|
+
NSString *userId = [serverSideVerificationOptions valueForKey:@"userId"];
|
|
96
|
+
|
|
97
|
+
if (userId != nil) {
|
|
98
|
+
options.userIdentifier = userId;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
NSString *customData = [serverSideVerificationOptions valueForKey:@"customData"];
|
|
102
|
+
|
|
103
|
+
if (customData != nil) {
|
|
104
|
+
options.customRewardString = customData;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
[rewardedInterstitialAd setServerSideVerificationOptions:options];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
RNGoogleMobileAdsFullScreenContentDelegate *fullScreenContentDelegate =
|
|
111
|
+
[[RNGoogleMobileAdsFullScreenContentDelegate alloc] init];
|
|
112
|
+
fullScreenContentDelegate.sendAdEvent = GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL;
|
|
113
|
+
fullScreenContentDelegate.requestId = requestId;
|
|
114
|
+
fullScreenContentDelegate.adUnitId = ad.adUnitID;
|
|
115
|
+
rewardedInterstitialAd.fullScreenContentDelegate = fullScreenContentDelegate;
|
|
116
|
+
rewardedInterstitialMap[requestId] = rewardedInterstitialAd;
|
|
117
|
+
rewardedInterstitialDelegateMap[requestId] = fullScreenContentDelegate;
|
|
118
|
+
GADAdReward *reward = rewardedInterstitialAd.adReward;
|
|
119
|
+
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
|
120
|
+
if (reward.type != nil) {
|
|
121
|
+
[data setValue:reward.type forKey:@"type"];
|
|
122
|
+
}
|
|
123
|
+
if (reward.amount != nil) {
|
|
124
|
+
[data setValue:reward.amount forKey:@"amount"];
|
|
125
|
+
}
|
|
126
|
+
[RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
|
|
127
|
+
requestId:requestId
|
|
128
|
+
type:GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED
|
|
129
|
+
adUnitId:ad.adUnitID
|
|
130
|
+
error:nil
|
|
131
|
+
data:data];
|
|
132
|
+
}];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
RCT_EXPORT_METHOD(rewardedInterstitialShow
|
|
136
|
+
: (nonnull NSNumber *)requestId
|
|
137
|
+
: (NSString *)adUnitId
|
|
138
|
+
: (NSDictionary *)showOptions
|
|
139
|
+
: (RCTPromiseResolveBlock)resolve
|
|
140
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
141
|
+
GADRewardedInterstitialAd *rewardedInterstitialAd = rewardedInterstitialMap[requestId];
|
|
142
|
+
|
|
143
|
+
if (rewardedInterstitialAd) {
|
|
144
|
+
[rewardedInterstitialAd
|
|
145
|
+
presentFromRootViewController:RCTSharedApplication().delegate.window.rootViewController
|
|
146
|
+
userDidEarnRewardHandler:^{
|
|
147
|
+
GADAdReward *reward = rewardedInterstitialAd.adReward;
|
|
148
|
+
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
|
149
|
+
if (reward.type != nil) {
|
|
150
|
+
[data setValue:reward.type forKey:@"type"];
|
|
151
|
+
}
|
|
152
|
+
if (reward.amount != nil) {
|
|
153
|
+
[data setValue:reward.amount forKey:@"amount"];
|
|
154
|
+
}
|
|
155
|
+
[RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
|
|
156
|
+
requestId:requestId
|
|
157
|
+
type:GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD
|
|
158
|
+
adUnitId:rewardedInterstitialAd.adUnitID
|
|
159
|
+
error:nil
|
|
160
|
+
data:data];
|
|
161
|
+
}];
|
|
162
|
+
} else {
|
|
163
|
+
[RNSharedUtils
|
|
164
|
+
rejectPromiseWithUserInfo:reject
|
|
165
|
+
userInfo:[@{
|
|
166
|
+
@"code" : @"not-ready",
|
|
167
|
+
@"message" :
|
|
168
|
+
@"Rewarded Interstitial ad attempted to show but was not ready.",
|
|
169
|
+
} mutableCopy]];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@end
|
|
@@ -12,7 +12,7 @@ var _validateAdRequestConfiguration = require("./validateAdRequestConfiguration"
|
|
|
12
12
|
var _version = require("./version");
|
|
13
13
|
|
|
14
14
|
const namespace = 'google_mobile_ads';
|
|
15
|
-
const nativeModuleName = ['RNGoogleMobileAdsModule', 'RNGoogleMobileAdsAppOpenModule', 'RNGoogleMobileAdsInterstitialModule', 'RNGoogleMobileAdsRewardedModule'];
|
|
15
|
+
const nativeModuleName = ['RNGoogleMobileAdsModule', 'RNGoogleMobileAdsAppOpenModule', 'RNGoogleMobileAdsInterstitialModule', 'RNGoogleMobileAdsRewardedModule', 'RNGoogleMobileAdsRewardedInterstitialModule'];
|
|
16
16
|
|
|
17
17
|
class MobileAdsModule extends _internal.Module {
|
|
18
18
|
constructor(app, config) {
|
|
@@ -26,6 +26,9 @@ class MobileAdsModule extends _internal.Module {
|
|
|
26
26
|
this.emitter.addListener('google_mobile_ads_rewarded_event', event => {
|
|
27
27
|
this.emitter.emit(`google_mobile_ads_rewarded_event:${event.adUnitId}:${event.requestId}`, event);
|
|
28
28
|
});
|
|
29
|
+
this.emitter.addListener('google_mobile_ads_rewarded_interstitial_event', event => {
|
|
30
|
+
this.emitter.emit(`google_mobile_ads_rewarded_interstitial_event:${event.adUnitId}:${event.requestId}`, event);
|
|
31
|
+
});
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
initialize() {
|
|
@@ -58,7 +61,7 @@ const MobileAdsInstance = new MobileAdsModule({
|
|
|
58
61
|
version: _version.version,
|
|
59
62
|
namespace,
|
|
60
63
|
nativeModuleName,
|
|
61
|
-
nativeEvents: ['google_mobile_ads_app_open_event', 'google_mobile_ads_interstitial_event', 'google_mobile_ads_rewarded_event']
|
|
64
|
+
nativeEvents: ['google_mobile_ads_app_open_event', 'google_mobile_ads_interstitial_event', 'google_mobile_ads_rewarded_event', 'google_mobile_ads_rewarded_interstitial_event']
|
|
62
65
|
});
|
|
63
66
|
|
|
64
67
|
const MobileAds = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["MobileAds.ts"],"names":["namespace","nativeModuleName","MobileAdsModule","Module","constructor","app","config","emitter","addListener","event","emit","adUnitId","requestId","initialize","native","setRequestConfiguration","requestConfiguration","e","Error","message","openAdInspector","MobileAdsInstance","name","version","nativeEvents","MobileAds"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAKA,MAAMA,SAAS,GAAG,mBAAlB;AAEA,MAAMC,gBAAgB,GAAG,CACvB,yBADuB,EAEvB,gCAFuB,EAGvB,qCAHuB,EAIvB,iCAJuB,CAAzB;;
|
|
1
|
+
{"version":3,"sources":["MobileAds.ts"],"names":["namespace","nativeModuleName","MobileAdsModule","Module","constructor","app","config","emitter","addListener","event","emit","adUnitId","requestId","initialize","native","setRequestConfiguration","requestConfiguration","e","Error","message","openAdInspector","MobileAdsInstance","name","version","nativeEvents","MobileAds"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAKA,MAAMA,SAAS,GAAG,mBAAlB;AAEA,MAAMC,gBAAgB,GAAG,CACvB,yBADuB,EAEvB,gCAFuB,EAGvB,qCAHuB,EAIvB,iCAJuB,EAKvB,6CALuB,CAAzB;;AAaA,MAAMC,eAAN,SAA8BC,gBAA9B,CAAyE;AACvEC,EAAAA,WAAW,CAACC,GAAD,EAAWC,MAAX,EAA2B;AACpC,UAAMD,GAAN,EAAWC,MAAX;AAEA,SAAKC,OAAL,CAAaC,WAAb,CAAyB,kCAAzB,EAA8DC,KAAD,IAAkB;AAC7E,WAAKF,OAAL,CAAaG,IAAb,CACG,oCAAmCD,KAAK,CAACE,QAAS,IAAGF,KAAK,CAACG,SAAU,EADxE,EAEEH,KAFF;AAID,KALD;AAOA,SAAKF,OAAL,CAAaC,WAAb,CAAyB,sCAAzB,EAAkEC,KAAD,IAAkB;AACjF,WAAKF,OAAL,CAAaG,IAAb,CACG,wCAAuCD,KAAK,CAACE,QAAS,IAAGF,KAAK,CAACG,SAAU,EAD5E,EAEEH,KAFF;AAID,KALD;AAOA,SAAKF,OAAL,CAAaC,WAAb,CAAyB,kCAAzB,EAA8DC,KAAD,IAAkB;AAC7E,WAAKF,OAAL,CAAaG,IAAb,CACG,oCAAmCD,KAAK,CAACE,QAAS,IAAGF,KAAK,CAACG,SAAU,EADxE,EAEEH,KAFF;AAID,KALD;AAOA,SAAKF,OAAL,CAAaC,WAAb,CAAyB,+CAAzB,EAA2EC,KAAD,IAAkB;AAC1F,WAAKF,OAAL,CAAaG,IAAb,CACG,iDAAgDD,KAAK,CAACE,QAAS,IAAGF,KAAK,CAACG,SAAU,EADrF,EAEEH,KAFF;AAID,KALD;AAMD;;AAEDI,EAAAA,UAAU,GAAG;AACX,WAAO,KAAKC,MAAL,CAAYD,UAAZ,EAAP;AACD;;AAEDE,EAAAA,uBAAuB,CAACC,oBAAD,EAA6C;AAClE,QAAIV,MAAJ;;AACA,QAAI;AACFA,MAAAA,MAAM,GAAG,oEAA+BU,oBAA/B,CAAT;AACD,KAFD,CAEE,OAAOC,CAAP,EAAU;AACV,UAAIA,CAAC,YAAYC,KAAjB,EAAwB;AACtB,cAAM,IAAIA,KAAJ,CAAW,8CAA6CD,CAAC,CAACE,OAAQ,EAAlE,CAAN;AACD;AACF;;AAED,WAAO,KAAKL,MAAL,CAAYC,uBAAZ,CAAoCT,MAApC,CAAP;AACD;;AAEDc,EAAAA,eAAe,GAAG;AAChB,WAAO,KAAKN,MAAL,CAAYM,eAAZ,EAAP;AACD;;AApDsE;;AAuDzE,MAAMC,iBAAiB,GAAG,IAAInB,eAAJ,CACxB;AAAEoB,EAAAA,IAAI,EAAE;AAAR,CADwB,EAExB;AACEC,EAAAA,OAAO,EAAPA,gBADF;AAEEvB,EAAAA,SAFF;AAGEC,EAAAA,gBAHF;AAIEuB,EAAAA,YAAY,EAAE,CACZ,kCADY,EAEZ,sCAFY,EAGZ,kCAHY,EAIZ,+CAJY;AAJhB,CAFwB,CAA1B;;AAeO,MAAMC,SAAS,GAAG,MAAM;AAC7B,SAAOJ,iBAAP;AACD,CAFM;;;eAIQI,S","sourcesContent":["import { Module } from './internal';\nimport { validateAdRequestConfiguration } from './validateAdRequestConfiguration';\nimport { version } from './version';\nimport { MobileAdsModuleInterface } from './types/MobileAdsModule.interface';\nimport { RequestConfiguration } from './types/RequestConfiguration';\nimport { App, Config } from './types/Module.interface';\n\nconst namespace = 'google_mobile_ads';\n\nconst nativeModuleName = [\n 'RNGoogleMobileAdsModule',\n 'RNGoogleMobileAdsAppOpenModule',\n 'RNGoogleMobileAdsInterstitialModule',\n 'RNGoogleMobileAdsRewardedModule',\n 'RNGoogleMobileAdsRewardedInterstitialModule',\n];\n\ntype Event = {\n adUnitId: string;\n requestId: number;\n};\n\nclass MobileAdsModule extends Module implements MobileAdsModuleInterface {\n constructor(app: App, config: Config) {\n super(app, config);\n\n this.emitter.addListener('google_mobile_ads_app_open_event', (event: Event) => {\n this.emitter.emit(\n `google_mobile_ads_app_open_event:${event.adUnitId}:${event.requestId}`,\n event,\n );\n });\n\n this.emitter.addListener('google_mobile_ads_interstitial_event', (event: Event) => {\n this.emitter.emit(\n `google_mobile_ads_interstitial_event:${event.adUnitId}:${event.requestId}`,\n event,\n );\n });\n\n this.emitter.addListener('google_mobile_ads_rewarded_event', (event: Event) => {\n this.emitter.emit(\n `google_mobile_ads_rewarded_event:${event.adUnitId}:${event.requestId}`,\n event,\n );\n });\n\n this.emitter.addListener('google_mobile_ads_rewarded_interstitial_event', (event: Event) => {\n this.emitter.emit(\n `google_mobile_ads_rewarded_interstitial_event:${event.adUnitId}:${event.requestId}`,\n event,\n );\n });\n }\n\n initialize() {\n return this.native.initialize();\n }\n\n setRequestConfiguration(requestConfiguration: RequestConfiguration) {\n let config;\n try {\n config = validateAdRequestConfiguration(requestConfiguration);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`googleMobileAds.setRequestConfiguration(*) ${e.message}`);\n }\n }\n\n return this.native.setRequestConfiguration(config);\n }\n\n openAdInspector() {\n return this.native.openAdInspector();\n }\n}\n\nconst MobileAdsInstance = new MobileAdsModule(\n { name: 'AppName' },\n {\n version,\n namespace,\n nativeModuleName,\n nativeEvents: [\n 'google_mobile_ads_app_open_event',\n 'google_mobile_ads_interstitial_event',\n 'google_mobile_ads_rewarded_event',\n 'google_mobile_ads_rewarded_interstitial_event',\n ],\n },\n);\n\nexport const MobileAds = () => {\n return MobileAdsInstance;\n};\n\nexport default MobileAds;\n"]}
|