react-native-google-mobile-ads 4.2.0 → 5.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.
Files changed (83) hide show
  1. package/RNGoogleMobileAds.podspec +16 -9
  2. package/__tests__/consent.test.ts +17 -9
  3. package/android/build.gradle +4 -3
  4. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java +111 -168
  5. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +1 -1
  6. package/docs/common-reasons-for-ads-not-showing.mdx +26 -24
  7. package/docs/displaying-ads-hook.mdx +99 -0
  8. package/docs/displaying-ads.mdx +3 -4
  9. package/docs/european-user-consent.mdx +67 -156
  10. package/docs/index.mdx +16 -16
  11. package/docs/migrating-to-v5.mdx +63 -0
  12. package/docs.json +4 -2
  13. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.h +0 -1
  14. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m +83 -124
  15. package/ios_config.sh +8 -0
  16. package/lib/commonjs/AdsConsent.js +58 -98
  17. package/lib/commonjs/AdsConsent.js.map +1 -1
  18. package/lib/commonjs/AdsConsentPurposes.js +47 -0
  19. package/lib/commonjs/AdsConsentPurposes.js.map +1 -0
  20. package/lib/commonjs/AdsConsentSpecialFeatures.js +39 -0
  21. package/lib/commonjs/AdsConsentSpecialFeatures.js.map +1 -0
  22. package/lib/commonjs/AdsConsentStatus.js +4 -3
  23. package/lib/commonjs/AdsConsentStatus.js.map +1 -1
  24. package/lib/commonjs/hooks/useAppOpenAd.js +51 -0
  25. package/lib/commonjs/hooks/useAppOpenAd.js.map +1 -0
  26. package/lib/commonjs/hooks/useFullScreenAd.js +120 -0
  27. package/lib/commonjs/hooks/useFullScreenAd.js.map +1 -0
  28. package/lib/commonjs/hooks/useInterstitialAd.js +51 -0
  29. package/lib/commonjs/hooks/useInterstitialAd.js.map +1 -0
  30. package/lib/commonjs/hooks/useRewardedAd.js +51 -0
  31. package/lib/commonjs/hooks/useRewardedAd.js.map +1 -0
  32. package/lib/commonjs/index.js +40 -0
  33. package/lib/commonjs/index.js.map +1 -1
  34. package/lib/commonjs/types/AdStates.js +6 -0
  35. package/lib/commonjs/types/AdStates.js.map +1 -0
  36. package/lib/commonjs/version.js +1 -1
  37. package/lib/commonjs/version.js.map +1 -1
  38. package/lib/module/AdsConsent.js +56 -98
  39. package/lib/module/AdsConsent.js.map +1 -1
  40. package/lib/module/AdsConsentPurposes.js +39 -0
  41. package/lib/module/AdsConsentPurposes.js.map +1 -0
  42. package/lib/module/AdsConsentSpecialFeatures.js +31 -0
  43. package/lib/module/AdsConsentSpecialFeatures.js.map +1 -0
  44. package/lib/module/AdsConsentStatus.js +4 -3
  45. package/lib/module/AdsConsentStatus.js.map +1 -1
  46. package/lib/module/hooks/useAppOpenAd.js +38 -0
  47. package/lib/module/hooks/useAppOpenAd.js.map +1 -0
  48. package/lib/module/hooks/useFullScreenAd.js +109 -0
  49. package/lib/module/hooks/useFullScreenAd.js.map +1 -0
  50. package/lib/module/hooks/useInterstitialAd.js +38 -0
  51. package/lib/module/hooks/useInterstitialAd.js.map +1 -0
  52. package/lib/module/hooks/useRewardedAd.js +38 -0
  53. package/lib/module/hooks/useRewardedAd.js.map +1 -0
  54. package/lib/module/index.js +5 -0
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/types/AdStates.js +2 -0
  57. package/lib/module/types/AdStates.js.map +1 -0
  58. package/lib/module/version.js +1 -1
  59. package/lib/module/version.js.map +1 -1
  60. package/lib/typescript/AdsConsentPurposes.d.ts +148 -0
  61. package/lib/typescript/AdsConsentSpecialFeatures.d.ts +22 -0
  62. package/lib/typescript/AdsConsentStatus.d.ts +10 -6
  63. package/lib/typescript/hooks/useAppOpenAd.d.ts +9 -0
  64. package/lib/typescript/hooks/useFullScreenAd.d.ts +5 -0
  65. package/lib/typescript/hooks/useInterstitialAd.d.ts +9 -0
  66. package/lib/typescript/hooks/useRewardedAd.d.ts +9 -0
  67. package/lib/typescript/index.d.ts +6 -1
  68. package/lib/typescript/types/AdStates.d.ts +85 -0
  69. package/lib/typescript/types/AdsConsent.interface.d.ts +229 -180
  70. package/lib/typescript/version.d.ts +1 -1
  71. package/package.json +10 -4
  72. package/src/AdsConsent.ts +91 -135
  73. package/src/AdsConsentPurposes.ts +182 -0
  74. package/src/AdsConsentSpecialFeatures.ts +48 -0
  75. package/src/AdsConsentStatus.ts +11 -6
  76. package/src/hooks/useAppOpenAd.ts +46 -0
  77. package/src/hooks/useFullScreenAd.ts +104 -0
  78. package/src/hooks/useInterstitialAd.ts +46 -0
  79. package/src/hooks/useRewardedAd.ts +46 -0
  80. package/src/index.ts +5 -0
  81. package/src/types/AdStates.ts +87 -0
  82. package/src/types/AdsConsent.interface.ts +230 -187
  83. package/src/version.ts +1 -1
@@ -0,0 +1,46 @@
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 { InterstitialAd } from '../ads/InterstitialAd';
22
+ import { AdHookReturns } from '../types/AdStates';
23
+ import { RequestOptions } from '../types/RequestOptions';
24
+
25
+ import { useFullScreenAd } from './useFullScreenAd';
26
+
27
+ /**
28
+ * React Hook for Interstitial Ad.
29
+ *
30
+ * @param adUnitId The Ad Unit ID for the 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 useInterstitialAd(
34
+ adUnitId: string | null,
35
+ requestOptions: RequestOptions = {},
36
+ ): Omit<AdHookReturns, 'adReward'> {
37
+ const [interstitialAd, setInterstitialAd] = useState<InterstitialAd | null>(null);
38
+
39
+ useDeepCompareEffect(() => {
40
+ setInterstitialAd(() => {
41
+ return adUnitId ? InterstitialAd.createForAdRequest(adUnitId, requestOptions) : null;
42
+ });
43
+ }, [adUnitId, requestOptions]);
44
+
45
+ return useFullScreenAd(interstitialAd);
46
+ }
@@ -0,0 +1,46 @@
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 { RewardedAd } from '../ads/RewardedAd';
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 Ad.
29
+ *
30
+ * @param adUnitId The Ad Unit ID for the Rewarded 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 useRewardedAd(
34
+ adUnitId: string | null,
35
+ requestOptions: RequestOptions = {},
36
+ ): Omit<AdHookReturns, 'adReward'> {
37
+ const [rewardedAd, setRewardedAd] = useState<RewardedAd | null>(null);
38
+
39
+ useDeepCompareEffect(() => {
40
+ setRewardedAd(() => {
41
+ return adUnitId ? RewardedAd.createForAdRequest(adUnitId, requestOptions) : null;
42
+ });
43
+ }, [adUnitId, requestOptions]);
44
+
45
+ return useFullScreenAd(rewardedAd);
46
+ }
package/src/index.ts CHANGED
@@ -22,6 +22,8 @@ export const SDK_VERSION = version;
22
22
 
23
23
  export { default, MobileAds } from './MobileAds';
24
24
  export { AdsConsentDebugGeography } from './AdsConsentDebugGeography';
25
+ export { AdsConsentPurposes } from './AdsConsentPurposes';
26
+ export { AdsConsentSpecialFeatures } from './AdsConsentSpecialFeatures';
25
27
  export { AdsConsentStatus } from './AdsConsentStatus';
26
28
  export { MaxAdContentRating } from './MaxAdContentRating';
27
29
  export { TestIds } from './TestIds';
@@ -33,3 +35,6 @@ export { AppOpenAd } from './ads/AppOpenAd';
33
35
  export { InterstitialAd } from './ads/InterstitialAd';
34
36
  export { RewardedAd } from './ads/RewardedAd';
35
37
  export { BannerAd } from './ads/BannerAd';
38
+ export { useAppOpenAd } from './hooks/useAppOpenAd';
39
+ export { useInterstitialAd } from './hooks/useInterstitialAd';
40
+ export { useRewardedAd } from './hooks/useRewardedAd';
@@ -0,0 +1,87 @@
1
+ import { AdShowOptions } from './AdShowOptions';
2
+ import { RewardedAdReward } from './RewardedAdReward';
3
+
4
+ export interface AdStates {
5
+ /**
6
+ * Whether the ad is loaded and ready to to be shown to the user.
7
+ */
8
+ isLoaded: boolean;
9
+ /**
10
+ * Whether the ad is opened.
11
+ */
12
+ isOpened: boolean;
13
+ /**
14
+ * Whether the user clicked the advert.
15
+ */
16
+ isClicked: boolean;
17
+ /**
18
+ * Whether the user closed the ad and has returned back to your application.
19
+ */
20
+ isClosed: boolean;
21
+ /**
22
+ * JavaScript Error containing the error code and message thrown by the Ad.
23
+ */
24
+ error?: Error;
25
+ /**
26
+ * Loaded reward item of the Rewarded Ad.
27
+ */
28
+ reward?: RewardedAdReward;
29
+ /**
30
+ * Whether the user earned the reward by Rewarded Ad.
31
+ */
32
+ isEarnedReward?: boolean;
33
+ }
34
+
35
+ export interface AdHookReturns extends AdStates {
36
+ /**
37
+ * Whether your ad is showing.
38
+ * The value is equal with `isOpened && !isClosed`.
39
+ */
40
+ isShowing: boolean;
41
+ /**
42
+ * Start loading the advert with the provided RequestOptions.
43
+ * #### Example
44
+ *
45
+ * ```jsx
46
+ * export default function App() {
47
+ * const interstitial = useInterstitialAd(TestIds.INTERSTITIAL, {
48
+ * requestNonPersonalizedAdsOnly: true,
49
+ * });
50
+ * useEffect(() => {
51
+ * interstitial.load();
52
+ * }, [interstitial.load]);
53
+ * }
54
+ * ```
55
+ */
56
+ load: () => void;
57
+ /**
58
+ * Show the loaded advert to the user.
59
+ *
60
+ * #### Example
61
+ *
62
+ * ```jsx
63
+ * export default function App() {
64
+ * const interstitial = useInterstitialAd(TestIds.INTERSTITIAL, {
65
+ * requestNonPersonalizedAdsOnly: true,
66
+ * });
67
+ * return (
68
+ * <View>
69
+ * <Button
70
+ * title="Navigate to next screen"
71
+ * onPress={() => {
72
+ * if (interstitial.isLoaded) {
73
+ * interstitial.show();
74
+ * } else {
75
+ * navigation.navigate('NextScreen');
76
+ * }
77
+ * }}
78
+ * />
79
+ * </View>
80
+ * )
81
+ * }
82
+ * ```
83
+ *
84
+ * @param showOptions An optional `AdShowOptions` interface.
85
+ */
86
+ show: (showOptions?: AdShowOptions) => void;
87
+ }