react-native-google-mobile-ads 6.0.0 → 6.2.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 (72) hide show
  1. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java +9 -3
  2. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java +2 -0
  3. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java +1 -0
  4. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.java +199 -0
  5. package/docs/displaying-ads-hook.mdx +1 -1
  6. package/docs/displaying-ads.mdx +132 -1
  7. package/docs/european-user-consent.mdx +31 -0
  8. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +1 -0
  9. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +7 -1
  10. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.h +25 -0
  11. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +173 -0
  12. package/lib/commonjs/BannerAdSize.js +2 -0
  13. package/lib/commonjs/BannerAdSize.js.map +1 -1
  14. package/lib/commonjs/MobileAds.js +5 -2
  15. package/lib/commonjs/MobileAds.js.map +1 -1
  16. package/lib/commonjs/TestIds.js +6 -2
  17. package/lib/commonjs/TestIds.js.map +1 -1
  18. package/lib/commonjs/ads/MobileAd.js +16 -4
  19. package/lib/commonjs/ads/MobileAd.js.map +1 -1
  20. package/lib/commonjs/ads/RewardedInterstitialAd.js +127 -0
  21. package/lib/commonjs/ads/RewardedInterstitialAd.js.map +1 -0
  22. package/lib/commonjs/hooks/useFullScreenAd.js.map +1 -1
  23. package/lib/commonjs/hooks/useRewardedAd.js.map +1 -1
  24. package/lib/commonjs/hooks/useRewardedInterstitialAd.js +51 -0
  25. package/lib/commonjs/hooks/useRewardedInterstitialAd.js.map +1 -0
  26. package/lib/commonjs/index.js +19 -1
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/version.js +1 -1
  29. package/lib/commonjs/version.js.map +1 -1
  30. package/lib/module/BannerAdSize.js +2 -0
  31. package/lib/module/BannerAdSize.js.map +1 -1
  32. package/lib/module/MobileAds.js +5 -2
  33. package/lib/module/MobileAds.js.map +1 -1
  34. package/lib/module/TestIds.js +6 -2
  35. package/lib/module/TestIds.js.map +1 -1
  36. package/lib/module/ads/MobileAd.js +16 -4
  37. package/lib/module/ads/MobileAd.js.map +1 -1
  38. package/lib/module/ads/RewardedInterstitialAd.js +130 -0
  39. package/lib/module/ads/RewardedInterstitialAd.js.map +1 -0
  40. package/lib/module/hooks/useFullScreenAd.js.map +1 -1
  41. package/lib/module/hooks/useRewardedAd.js.map +1 -1
  42. package/lib/module/hooks/useRewardedInterstitialAd.js +38 -0
  43. package/lib/module/hooks/useRewardedInterstitialAd.js.map +1 -0
  44. package/lib/module/index.js +2 -0
  45. package/lib/module/index.js.map +1 -1
  46. package/lib/module/version.js +1 -1
  47. package/lib/module/version.js.map +1 -1
  48. package/lib/typescript/BannerAdSize.d.ts +10 -1
  49. package/lib/typescript/MobileAds.d.ts +1 -1
  50. package/lib/typescript/TestIds.d.ts +2 -0
  51. package/lib/typescript/ads/MobileAd.d.ts +3 -2
  52. package/lib/typescript/ads/RewardedInterstitialAd.d.ts +82 -0
  53. package/lib/typescript/hooks/useFullScreenAd.d.ts +2 -1
  54. package/lib/typescript/hooks/useRewardedAd.d.ts +1 -1
  55. package/lib/typescript/hooks/useRewardedInterstitialAd.d.ts +9 -0
  56. package/lib/typescript/index.d.ts +3 -1
  57. package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +12 -7
  58. package/lib/typescript/types/MobileAdsModule.interface.d.ts +1 -1
  59. package/lib/typescript/version.d.ts +1 -1
  60. package/package.json +8 -8
  61. package/src/BannerAdSize.ts +12 -1
  62. package/src/MobileAds.ts +9 -0
  63. package/src/TestIds.ts +4 -0
  64. package/src/ads/MobileAd.ts +16 -6
  65. package/src/ads/RewardedInterstitialAd.ts +143 -0
  66. package/src/hooks/useFullScreenAd.ts +4 -3
  67. package/src/hooks/useRewardedAd.ts +1 -1
  68. package/src/hooks/useRewardedInterstitialAd.ts +47 -0
  69. package/src/index.ts +2 -0
  70. package/src/types/GoogleMobileAdsNativeModule.ts +16 -7
  71. package/src/types/MobileAdsModule.interface.ts +1 -1
  72. package/src/version.ts +1 -1
@@ -0,0 +1,143 @@
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 { isString } from '../common';
19
+ import { MobileAds } from '../MobileAds';
20
+ import { validateAdRequestOptions } from '../validateAdRequestOptions';
21
+ import { MobileAd } from './MobileAd';
22
+ import { AdEventType } from '../AdEventType';
23
+ import { RewardedAdEventType } from '../RewardedAdEventType';
24
+ import { AdEventListener } from '../types/AdEventListener';
25
+ import { AdEventsListener } from '../types/AdEventsListener';
26
+ import { RequestOptions } from '../types/RequestOptions';
27
+
28
+ /**
29
+ * A class for interacting and showing Rewarded Interstitial Ads.
30
+ *
31
+ * An Rewarded Interstitial advert can be pre-loaded and shown at a suitable point in your apps flow, such as at the end of a level
32
+ * in a game. The content of a rewarded interstital advert can be controlled via your Google Mobile Ads dashboard. Typically users are rewarded
33
+ * after completing a specific advert action (e.g. watching a video or submitting an option via an interactive form).
34
+ * Events (such as the user earning a reward or closing a rewarded interstital advert early) are sent back for you to handle accordingly
35
+ * within your application.
36
+ *
37
+ * #### Example
38
+ *
39
+ * First create a new Rewarded Interstitial instance, passing in your Ad Unit ID from the Google Mobile Ads configuration console, and any additional
40
+ * request options. The example below will present a test advert, and only request a non-personalized ad.
41
+ *
42
+ * ```js
43
+ * import { RewardedInterstitialAd, TestIds } from 'react-native-google-mobile-ads';
44
+ *
45
+ * const rewardedInterstitial = RewardedInterstitialAd.createForAdRequest(TestIds.REWARDED_INTERSTITIAL, {
46
+ * requestNonPersonalizedAdsOnly: true,
47
+ * });
48
+ * ```
49
+ *
50
+ * Each advert needs to be loaded from Google Mobile Ads before being shown. It is recommended this is performed before the user
51
+ * reaches the checkpoint to show the advert, so it's ready to go. Before loading the advert, we need to setup
52
+ * event listeners to listen for updates from Google Mobile Ads, such as advert loaded or failed to load.
53
+ *
54
+ * Event types match the `AdEventType` or `RewardedAdEventType` interface. The potential user reward for rewarded interstitial
55
+ * adverts are passed back to the event handler on advert load and when the user earns the reward.
56
+ *
57
+ * ```js
58
+ * import { RewardedAdEventType } from 'react-native-google-mobile-ads';
59
+ *
60
+ * rewardedInterstitial.addAdEventListener(RewardedAdEventType.LOADED. () => {
61
+ * rewarded.show();
62
+ * });
63
+ * rewardedInterstitial.addAdEventListener(RewardedAdEventType.EARNED_REWARD. (reward) => {
64
+ * console.log('User earned reward of ', reward);
65
+ * });
66
+ *
67
+ * rewardedInterstitial.load();
68
+ * ```
69
+ *
70
+ * The rewarded interstitial advert will be presented to the user, and several more events can be triggered such as the user clicking the
71
+ * advert, closing it or completing the action.
72
+ */
73
+ export class RewardedInterstitialAd extends MobileAd {
74
+ protected static _rewardedInterstitialRequest = 0;
75
+ /**
76
+ * Creates a new RewardedInterstitialAd instance.
77
+ *
78
+ * #### Example
79
+ *
80
+ * ```js
81
+ * import { RewardedInterstitialAd, RewardedAdEventType, TestIds } from 'react-native-google-mobile-ads';
82
+ *
83
+ * const rewardedInterstitialAd = await RewardedInterstitialAd.createForAdRequest(TestIds.REWARDED_INTERSTITIAL, {
84
+ * requestAgent: 'CoolAds',
85
+ * });
86
+ *
87
+ * rewardedInterstitialAd.addAdEventListener(RewardedAdEventType.LOADED. () => {
88
+ * rewardedInterstitialAd.show();
89
+ * });
90
+ * rewardedInterstitialAd.addAdEventListener(RewardedAdEventType.EARNED_REWARD. (reward) => {
91
+ * console.log('User earned reward of ', reward);
92
+ * });
93
+ *
94
+ * rewardedInterstitialAd.load();
95
+ * ```
96
+ *
97
+ * @param adUnitId The Ad Unit ID for the Rewarded Interstitial Ad. You can find this on your Google Mobile Ads dashboard.
98
+ * @param requestOptions Optional RequestOptions used to load the ad.
99
+ */
100
+ static createForAdRequest(adUnitId: string, requestOptions?: RequestOptions) {
101
+ if (!isString(adUnitId)) {
102
+ throw new Error(
103
+ "RewardedInterstitialAd.createForAdRequest(*) 'adUnitId' expected an string value.",
104
+ );
105
+ }
106
+
107
+ let options = {};
108
+ try {
109
+ options = validateAdRequestOptions(requestOptions);
110
+ } catch (e) {
111
+ if (e instanceof Error) {
112
+ throw new Error(`RewardedInterstitialAd.createForAdRequest(_, *) ${e.message}.`);
113
+ }
114
+ }
115
+
116
+ const requestId = RewardedInterstitialAd._rewardedInterstitialRequest++;
117
+ return new RewardedInterstitialAd(
118
+ 'rewarded_interstitial',
119
+ MobileAds(),
120
+ requestId,
121
+ adUnitId,
122
+ options,
123
+ );
124
+ }
125
+
126
+ addAdEventsListener<T extends AdEventType | RewardedAdEventType>(
127
+ listener: AdEventsListener<T>,
128
+ ): () => void {
129
+ return this._addAdEventsListener(listener);
130
+ }
131
+
132
+ addAdEventListener<T extends AdEventType | RewardedAdEventType>(
133
+ type: T,
134
+ listener: AdEventListener<T>,
135
+ ) {
136
+ if (type === AdEventType.LOADED) {
137
+ throw new Error(
138
+ 'RewardedInterstitialAd.addAdEventListener(*) use RewardedAdEventType.LOADED instead of AdEventType.LOADED.',
139
+ );
140
+ }
141
+ return this._addAdEventListener(type, listener);
142
+ }
143
+ }
@@ -21,6 +21,7 @@ import { AdEventType } from '../AdEventType';
21
21
  import { AppOpenAd } from '../ads/AppOpenAd';
22
22
  import { InterstitialAd } from '../ads/InterstitialAd';
23
23
  import { RewardedAd } from '../ads/RewardedAd';
24
+ import { RewardedInterstitialAd } from '../ads/RewardedInterstitialAd';
24
25
  import { RewardedAdEventType } from '../RewardedAdEventType';
25
26
  import { AdStates, AdHookReturns } from '../types/AdStates';
26
27
  import { AdShowOptions } from '../types/AdShowOptions';
@@ -36,9 +37,9 @@ const initialState: AdStates = {
36
37
  isEarnedReward: false,
37
38
  };
38
39
 
39
- export function useFullScreenAd<T extends InterstitialAd | RewardedAd | AppOpenAd | null>(
40
- ad: T,
41
- ): AdHookReturns {
40
+ export function useFullScreenAd<
41
+ T extends AppOpenAd | InterstitialAd | RewardedAd | RewardedInterstitialAd | null,
42
+ >(ad: T): AdHookReturns {
42
43
  const [state, setState] = useReducer<Reducer<AdStates, Partial<AdStates>>>(
43
44
  (prevState, newState) => ({ ...prevState, ...newState }),
44
45
  initialState,
@@ -33,7 +33,7 @@ import { useFullScreenAd } from './useFullScreenAd';
33
33
  export function useRewardedAd(
34
34
  adUnitId: string | null,
35
35
  requestOptions: RequestOptions = {},
36
- ): Omit<AdHookReturns, 'adReward'> {
36
+ ): AdHookReturns {
37
37
  const [rewardedAd, setRewardedAd] = useState<RewardedAd | null>(null);
38
38
 
39
39
  useDeepCompareEffect(() => {
@@ -0,0 +1,47 @@
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 { useState } from 'react';
19
+ import useDeepCompareEffect from 'use-deep-compare-effect';
20
+
21
+ import { RewardedInterstitialAd } from '../ads/RewardedInterstitialAd';
22
+ import { AdHookReturns } from '../types/AdStates';
23
+ import { RequestOptions } from '../types/RequestOptions';
24
+
25
+ import { useFullScreenAd } from './useFullScreenAd';
26
+
27
+ /**
28
+ * React Hook for Rewarded Interstitial Ad.
29
+ *
30
+ * @param adUnitId The Ad Unit ID for the Rewarded Interstitial Ad. You can find this on your Google Mobile Ads dashboard. You can destroy ad instance by setting this value to null.
31
+ * @param requestOptions Optional RequestOptions used to load the ad.
32
+ */
33
+ export function useRewardedInterstitialAd(
34
+ adUnitId: string | null,
35
+ requestOptions: RequestOptions = {},
36
+ ): AdHookReturns {
37
+ const [rewardedInterstitialAd, setRewardedInterstitialAd] =
38
+ useState<RewardedInterstitialAd | null>(null);
39
+
40
+ useDeepCompareEffect(() => {
41
+ setRewardedInterstitialAd(() => {
42
+ return adUnitId ? RewardedInterstitialAd.createForAdRequest(adUnitId, requestOptions) : null;
43
+ });
44
+ }, [adUnitId, requestOptions]);
45
+
46
+ return useFullScreenAd(rewardedInterstitialAd);
47
+ }
package/src/index.ts CHANGED
@@ -35,10 +35,12 @@ export { AdsConsent } from './AdsConsent';
35
35
  export { AppOpenAd } from './ads/AppOpenAd';
36
36
  export { InterstitialAd } from './ads/InterstitialAd';
37
37
  export { RewardedAd } from './ads/RewardedAd';
38
+ export { RewardedInterstitialAd } from './ads/RewardedInterstitialAd';
38
39
  export { BannerAd } from './ads/BannerAd';
39
40
  export { GAMBannerAd } from './ads/GAMBannerAd';
40
41
  export { GAMInterstitialAd } from './ads/GAMInterstitialAd';
41
42
  export { useAppOpenAd } from './hooks/useAppOpenAd';
42
43
  export { useInterstitialAd } from './hooks/useInterstitialAd';
43
44
  export { useRewardedAd } from './hooks/useRewardedAd';
45
+ export { useRewardedInterstitialAd } from './hooks/useRewardedInterstitialAd';
44
46
  export * from './types';
@@ -3,14 +3,23 @@ import { RequestConfiguration } from './RequestConfiguration';
3
3
  import { RequestOptions } from './RequestOptions';
4
4
  import { AdShowOptions } from './AdShowOptions';
5
5
 
6
+ type AdLoadFunction = (requestId: number, adUnitId: string, requestOptions: RequestOptions) => void;
7
+ type AdShowFunction = (
8
+ requestId: number,
9
+ adUnitId: string,
10
+ showOptions?: AdShowOptions,
11
+ ) => Promise<void>;
12
+
6
13
  export interface GoogleMobileAdsNativeModule {
7
14
  initialize(): Promise<AdapterStatus[]>;
8
15
  setRequestConfiguration(requestConfiguration?: RequestConfiguration): Promise<void>;
9
- openAdInspector(): () => Promise<void>;
10
- appOpenLoad(requestId: number, adUnitId: string, requestOptions: RequestOptions): void;
11
- appOpenShow(requestId: number, adUnitId: string, showOptions?: AdShowOptions): Promise<void>;
12
- interstitialLoad(requestId: number, adUnitId: string, requestOptions: RequestOptions): void;
13
- interstitialShow(requestId: number, adUnitId: string, showOptions?: AdShowOptions): Promise<void>;
14
- rewardedLoad(requestId: number, adUnitId: string, requestOptions: RequestOptions): void;
15
- rewardedShow(requestId: number, adUnitId: string, showOptions?: AdShowOptions): Promise<void>;
16
+ openAdInspector(): Promise<void>;
17
+ appOpenLoad: AdLoadFunction;
18
+ appOpenShow: AdShowFunction;
19
+ interstitialLoad: AdLoadFunction;
20
+ interstitialShow: AdShowFunction;
21
+ rewardedLoad: AdLoadFunction;
22
+ rewardedShow: AdShowFunction;
23
+ rewardedInterstitialLoad: AdLoadFunction;
24
+ rewardedInterstitialShow: AdShowFunction;
16
25
  }
@@ -39,7 +39,7 @@ export interface MobileAdsModuleInterface {
39
39
  *
40
40
  * @see https://developers.google.com/ad-manager/mobile-ads-sdk/android/ad-inspector
41
41
  */
42
- openAdInspector(): () => Promise<void>;
42
+ openAdInspector(): Promise<void>;
43
43
 
44
44
  /**
45
45
  * The native module instance for the Google Mobile Ads service.
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '6.0.0';
2
+ export const version = '6.2.0';