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.
- package/RNGoogleMobileAds.podspec +16 -9
- package/__tests__/consent.test.ts +17 -9
- package/android/build.gradle +4 -3
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java +111 -168
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +1 -1
- package/docs/common-reasons-for-ads-not-showing.mdx +26 -24
- package/docs/displaying-ads-hook.mdx +99 -0
- package/docs/displaying-ads.mdx +3 -4
- package/docs/european-user-consent.mdx +67 -156
- package/docs/index.mdx +16 -16
- package/docs/migrating-to-v5.mdx +63 -0
- package/docs.json +4 -2
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.h +0 -1
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m +83 -124
- package/ios_config.sh +8 -0
- package/lib/commonjs/AdsConsent.js +58 -98
- package/lib/commonjs/AdsConsent.js.map +1 -1
- package/lib/commonjs/AdsConsentPurposes.js +47 -0
- package/lib/commonjs/AdsConsentPurposes.js.map +1 -0
- package/lib/commonjs/AdsConsentSpecialFeatures.js +39 -0
- package/lib/commonjs/AdsConsentSpecialFeatures.js.map +1 -0
- package/lib/commonjs/AdsConsentStatus.js +4 -3
- package/lib/commonjs/AdsConsentStatus.js.map +1 -1
- package/lib/commonjs/hooks/useAppOpenAd.js +51 -0
- package/lib/commonjs/hooks/useAppOpenAd.js.map +1 -0
- package/lib/commonjs/hooks/useFullScreenAd.js +120 -0
- package/lib/commonjs/hooks/useFullScreenAd.js.map +1 -0
- package/lib/commonjs/hooks/useInterstitialAd.js +51 -0
- package/lib/commonjs/hooks/useInterstitialAd.js.map +1 -0
- package/lib/commonjs/hooks/useRewardedAd.js +51 -0
- package/lib/commonjs/hooks/useRewardedAd.js.map +1 -0
- package/lib/commonjs/index.js +40 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/AdStates.js +6 -0
- package/lib/commonjs/types/AdStates.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/AdsConsent.js +56 -98
- package/lib/module/AdsConsent.js.map +1 -1
- package/lib/module/AdsConsentPurposes.js +39 -0
- package/lib/module/AdsConsentPurposes.js.map +1 -0
- package/lib/module/AdsConsentSpecialFeatures.js +31 -0
- package/lib/module/AdsConsentSpecialFeatures.js.map +1 -0
- package/lib/module/AdsConsentStatus.js +4 -3
- package/lib/module/AdsConsentStatus.js.map +1 -1
- package/lib/module/hooks/useAppOpenAd.js +38 -0
- package/lib/module/hooks/useAppOpenAd.js.map +1 -0
- package/lib/module/hooks/useFullScreenAd.js +109 -0
- package/lib/module/hooks/useFullScreenAd.js.map +1 -0
- package/lib/module/hooks/useInterstitialAd.js +38 -0
- package/lib/module/hooks/useInterstitialAd.js.map +1 -0
- package/lib/module/hooks/useRewardedAd.js +38 -0
- package/lib/module/hooks/useRewardedAd.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/AdStates.js +2 -0
- package/lib/module/types/AdStates.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/AdsConsentPurposes.d.ts +148 -0
- package/lib/typescript/AdsConsentSpecialFeatures.d.ts +22 -0
- package/lib/typescript/AdsConsentStatus.d.ts +10 -6
- package/lib/typescript/hooks/useAppOpenAd.d.ts +9 -0
- package/lib/typescript/hooks/useFullScreenAd.d.ts +5 -0
- package/lib/typescript/hooks/useInterstitialAd.d.ts +9 -0
- package/lib/typescript/hooks/useRewardedAd.d.ts +9 -0
- package/lib/typescript/index.d.ts +6 -1
- package/lib/typescript/types/AdStates.d.ts +85 -0
- package/lib/typescript/types/AdsConsent.interface.d.ts +229 -180
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +10 -4
- package/src/AdsConsent.ts +91 -135
- package/src/AdsConsentPurposes.ts +182 -0
- package/src/AdsConsentSpecialFeatures.ts +48 -0
- package/src/AdsConsentStatus.ts +11 -6
- package/src/hooks/useAppOpenAd.ts +46 -0
- package/src/hooks/useFullScreenAd.ts +104 -0
- package/src/hooks/useInterstitialAd.ts +46 -0
- package/src/hooks/useRewardedAd.ts +46 -0
- package/src/index.ts +5 -0
- package/src/types/AdStates.ts +87 -0
- package/src/types/AdsConsent.interface.ts +230 -187
- 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
|
+
}
|