react-native-google-mobile-ads 4.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/LICENSE +32 -0
- package/README.md +65 -0
- package/RNGoogleMobileAds.podspec +42 -0
- package/__tests__/consent.test.ts +25 -0
- package/__tests__/googleMobileAds.test.ts +63 -0
- package/__tests__/interstitial.test.ts +53 -0
- package/__tests__/requestOptions.test.tsx +4 -0
- package/__tests__/rewarded.test.tsx +4 -0
- package/__tests__/showOptions.test.tsx +4 -0
- package/android/.editorconfig +10 -0
- package/android/app-json.gradle +69 -0
- package/android/build.gradle +98 -0
- package/android/lint.xml +5 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +17 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java +169 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +161 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java +209 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java +256 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java +226 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java +72 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +159 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +143 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java +48 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.java +177 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/RCTConvert.java +111 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeApp.java +34 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeEvent.java +41 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeEventEmitter.java +150 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeInitProvider.java +77 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeJSON.java +107 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeMeta.java +92 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeModule.java +96 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativePreferences.java +86 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/SharedUtils.java +427 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/TaskExecutorService.java +124 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/ContextProvider.java +30 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/NativeError.java +28 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/NativeEvent.java +26 -0
- package/babel.config.js +18 -0
- package/docs/displaying-ads.mdx +319 -0
- package/docs/european-user-consent.mdx +258 -0
- package/docs/img/logo_admob_192px.svg +19 -0
- package/docs/index.mdx +168 -0
- package/docs.json +9 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.h +29 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +98 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.h +23 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.m +153 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +60 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +201 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.h +26 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m +179 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +32 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +57 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +124 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.h +24 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m +104 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +173 -0
- package/ios/RNGoogleMobileAds/common/RNAppModule.h +24 -0
- package/ios/RNGoogleMobileAds/common/RNAppModule.m +158 -0
- package/ios/RNGoogleMobileAds/common/RNJSON.h +34 -0
- package/ios/RNGoogleMobileAds/common/RNJSON.m +93 -0
- package/ios/RNGoogleMobileAds/common/RNMeta.h +30 -0
- package/ios/RNGoogleMobileAds/common/RNMeta.m +61 -0
- package/ios/RNGoogleMobileAds/common/RNPreferences.h +44 -0
- package/ios/RNGoogleMobileAds/common/RNPreferences.m +94 -0
- package/ios/RNGoogleMobileAds/common/RNRCTEventEmitter.h +73 -0
- package/ios/RNGoogleMobileAds/common/RNRCTEventEmitter.m +150 -0
- package/ios/RNGoogleMobileAds/common/RNSharedUtils.h +48 -0
- package/ios/RNGoogleMobileAds/common/RNSharedUtils.m +56 -0
- package/ios/RNGoogleMobileAds.xcodeproj/project.pbxproj +377 -0
- package/ios/RNGoogleMobileAds.xcodeproj/xcshareddata/IDETemplateMacros.plist +24 -0
- package/ios_config.sh +140 -0
- package/jest.config.js +6 -0
- package/jest.setup.ts +29 -0
- package/lib/commonjs/AdEventType.js +34 -0
- package/lib/commonjs/AdEventType.js.map +1 -0
- package/lib/commonjs/AdsConsent.js +160 -0
- package/lib/commonjs/AdsConsent.js.map +1 -0
- package/lib/commonjs/AdsConsentDebugGeography.js +38 -0
- package/lib/commonjs/AdsConsentDebugGeography.js.map +1 -0
- package/lib/commonjs/AdsConsentStatus.js +36 -0
- package/lib/commonjs/AdsConsentStatus.js.map +1 -0
- package/lib/commonjs/BannerAdSize.js +38 -0
- package/lib/commonjs/BannerAdSize.js.map +1 -0
- package/lib/commonjs/MaxAdContentRating.js +33 -0
- package/lib/commonjs/MaxAdContentRating.js.map +1 -0
- package/lib/commonjs/MobileAds.js +67 -0
- package/lib/commonjs/MobileAds.js.map +1 -0
- package/lib/commonjs/RewardedAdEventType.js +31 -0
- package/lib/commonjs/RewardedAdEventType.js.map +1 -0
- package/lib/commonjs/TestIds.js +47 -0
- package/lib/commonjs/TestIds.js.map +1 -0
- package/lib/commonjs/ads/AppOpenAd.js +96 -0
- package/lib/commonjs/ads/AppOpenAd.js.map +1 -0
- package/lib/commonjs/ads/BannerAd.js +128 -0
- package/lib/commonjs/ads/BannerAd.js.map +1 -0
- package/lib/commonjs/ads/InterstitialAd.js +163 -0
- package/lib/commonjs/ads/InterstitialAd.js.map +1 -0
- package/lib/commonjs/ads/MobileAd.js +90 -0
- package/lib/commonjs/ads/MobileAd.js.map +1 -0
- package/lib/commonjs/ads/RewardedAd.js +169 -0
- package/lib/commonjs/ads/RewardedAd.js.map +1 -0
- package/lib/commonjs/common/Base64.js +121 -0
- package/lib/commonjs/common/Base64.js.map +1 -0
- package/lib/commonjs/common/MutatableParams.js +46 -0
- package/lib/commonjs/common/MutatableParams.js.map +1 -0
- package/lib/commonjs/common/ReferenceBase.js +59 -0
- package/lib/commonjs/common/ReferenceBase.js.map +1 -0
- package/lib/commonjs/common/deeps.js +101 -0
- package/lib/commonjs/common/deeps.js.map +1 -0
- package/lib/commonjs/common/id.js +82 -0
- package/lib/commonjs/common/id.js.map +1 -0
- package/lib/commonjs/common/index.js +212 -0
- package/lib/commonjs/common/index.js.map +1 -0
- package/lib/commonjs/common/path.js +144 -0
- package/lib/commonjs/common/path.js.map +1 -0
- package/lib/commonjs/common/promise.js +70 -0
- package/lib/commonjs/common/promise.js.map +1 -0
- package/lib/commonjs/common/serialize.js +52 -0
- package/lib/commonjs/common/serialize.js.map +1 -0
- package/lib/commonjs/common/validate.js +239 -0
- package/lib/commonjs/common/validate.js.map +1 -0
- package/lib/commonjs/declarations.d.js +2 -0
- package/lib/commonjs/declarations.d.js.map +1 -0
- package/lib/commonjs/index.js +143 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js +76 -0
- package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -0
- package/lib/commonjs/internal/Module.js +60 -0
- package/lib/commonjs/internal/Module.js.map +1 -0
- package/lib/commonjs/internal/NativeError.js +70 -0
- package/lib/commonjs/internal/NativeError.js.map +1 -0
- package/lib/commonjs/internal/SharedEventEmitter.js +31 -0
- package/lib/commonjs/internal/SharedEventEmitter.js.map +1 -0
- package/lib/commonjs/internal/constants.js +30 -0
- package/lib/commonjs/internal/constants.js.map +1 -0
- package/lib/commonjs/internal/index.js +49 -0
- package/lib/commonjs/internal/index.js.map +1 -0
- package/lib/commonjs/internal/registry/nativeModule.js +231 -0
- package/lib/commonjs/internal/registry/nativeModule.js.map +1 -0
- package/lib/commonjs/types/AdEventListener.js +6 -0
- package/lib/commonjs/types/AdEventListener.js.map +1 -0
- package/lib/commonjs/types/AdShowOptions.js +2 -0
- package/lib/commonjs/types/AdShowOptions.js.map +1 -0
- package/lib/commonjs/types/AdapterStatus.js +18 -0
- package/lib/commonjs/types/AdapterStatus.js.map +1 -0
- package/lib/commonjs/types/AdsConsent.interface.js +6 -0
- package/lib/commonjs/types/AdsConsent.interface.js.map +1 -0
- package/lib/commonjs/types/BannerAdProps.js +6 -0
- package/lib/commonjs/types/BannerAdProps.js.map +1 -0
- package/lib/commonjs/types/GoogleMobileAdsNativeModule.js +6 -0
- package/lib/commonjs/types/GoogleMobileAdsNativeModule.js.map +1 -0
- package/lib/commonjs/types/MobileAd.interface.js +6 -0
- package/lib/commonjs/types/MobileAd.interface.js.map +1 -0
- package/lib/commonjs/types/MobileAdsModule.interface.js +6 -0
- package/lib/commonjs/types/MobileAdsModule.interface.js.map +1 -0
- package/lib/commonjs/types/Module.interface.js +2 -0
- package/lib/commonjs/types/Module.interface.js.map +1 -0
- package/lib/commonjs/types/RequestConfiguration.js +6 -0
- package/lib/commonjs/types/RequestConfiguration.js.map +1 -0
- package/lib/commonjs/types/RequestOptions.js +2 -0
- package/lib/commonjs/types/RequestOptions.js.map +1 -0
- package/lib/commonjs/types/RewardedAdReward.js +2 -0
- package/lib/commonjs/types/RewardedAdReward.js.map +1 -0
- package/lib/commonjs/validateAdRequestConfiguration.js +69 -0
- package/lib/commonjs/validateAdRequestConfiguration.js.map +1 -0
- package/lib/commonjs/validateAdRequestOptions.js +158 -0
- package/lib/commonjs/validateAdRequestOptions.js.map +1 -0
- package/lib/commonjs/validateAdShowOptions.js +47 -0
- package/lib/commonjs/validateAdShowOptions.js.map +1 -0
- package/lib/commonjs/version.js +10 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/AdEventType.js +26 -0
- package/lib/module/AdEventType.js.map +1 -0
- package/lib/module/AdsConsent.js +148 -0
- package/lib/module/AdsConsent.js.map +1 -0
- package/lib/module/AdsConsentDebugGeography.js +30 -0
- package/lib/module/AdsConsentDebugGeography.js.map +1 -0
- package/lib/module/AdsConsentStatus.js +28 -0
- package/lib/module/AdsConsentStatus.js.map +1 -0
- package/lib/module/BannerAdSize.js +30 -0
- package/lib/module/BannerAdSize.js.map +1 -0
- package/lib/module/MaxAdContentRating.js +25 -0
- package/lib/module/MaxAdContentRating.js.map +1 -0
- package/lib/module/MobileAds.js +53 -0
- package/lib/module/MobileAds.js.map +1 -0
- package/lib/module/RewardedAdEventType.js +23 -0
- package/lib/module/RewardedAdEventType.js.map +1 -0
- package/lib/module/TestIds.js +38 -0
- package/lib/module/TestIds.js.map +1 -0
- package/lib/module/ads/AppOpenAd.js +81 -0
- package/lib/module/ads/AppOpenAd.js.map +1 -0
- package/lib/module/ads/BannerAd.js +108 -0
- package/lib/module/ads/BannerAd.js.map +1 -0
- package/lib/module/ads/InterstitialAd.js +149 -0
- package/lib/module/ads/InterstitialAd.js.map +1 -0
- package/lib/module/ads/MobileAd.js +94 -0
- package/lib/module/ads/MobileAd.js.map +1 -0
- package/lib/module/ads/RewardedAd.js +155 -0
- package/lib/module/ads/RewardedAd.js.map +1 -0
- package/lib/module/common/Base64.js +106 -0
- package/lib/module/common/Base64.js.map +1 -0
- package/lib/module/common/MutatableParams.js +52 -0
- package/lib/module/common/MutatableParams.js.map +1 -0
- package/lib/module/common/ReferenceBase.js +50 -0
- package/lib/module/common/ReferenceBase.js.map +1 -0
- package/lib/module/common/deeps.js +91 -0
- package/lib/module/common/deeps.js.map +1 -0
- package/lib/module/common/id.js +74 -0
- package/lib/module/common/id.js.map +1 -0
- package/lib/module/common/index.js +109 -0
- package/lib/module/common/index.js.map +1 -0
- package/lib/module/common/path.js +120 -0
- package/lib/module/common/path.js.map +1 -0
- package/lib/module/common/promise.js +60 -0
- package/lib/module/common/promise.js.map +1 -0
- package/lib/module/common/serialize.js +41 -0
- package/lib/module/common/serialize.js.map +1 -0
- package/lib/module/common/validate.js +197 -0
- package/lib/module/common/validate.js.map +1 -0
- package/lib/module/declarations.d.js +2 -0
- package/lib/module/declarations.d.js.map +1 -0
- package/lib/module/index.js +33 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js +83 -0
- package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -0
- package/lib/module/internal/Module.js +64 -0
- package/lib/module/internal/Module.js.map +1 -0
- package/lib/module/internal/NativeError.js +61 -0
- package/lib/module/internal/NativeError.js.map +1 -0
- package/lib/module/internal/SharedEventEmitter.js +20 -0
- package/lib/module/internal/SharedEventEmitter.js.map +1 -0
- package/lib/module/internal/constants.js +20 -0
- package/lib/module/internal/constants.js.map +1 -0
- package/lib/module/internal/index.js +21 -0
- package/lib/module/internal/index.js.map +1 -0
- package/lib/module/internal/registry/nativeModule.js +215 -0
- package/lib/module/internal/registry/nativeModule.js.map +1 -0
- package/lib/module/types/AdEventListener.js +2 -0
- package/lib/module/types/AdEventListener.js.map +1 -0
- package/lib/module/types/AdShowOptions.js +2 -0
- package/lib/module/types/AdShowOptions.js.map +1 -0
- package/lib/module/types/AdapterStatus.js +10 -0
- package/lib/module/types/AdapterStatus.js.map +1 -0
- package/lib/module/types/AdsConsent.interface.js +2 -0
- package/lib/module/types/AdsConsent.interface.js.map +1 -0
- package/lib/module/types/BannerAdProps.js +2 -0
- package/lib/module/types/BannerAdProps.js.map +1 -0
- package/lib/module/types/GoogleMobileAdsNativeModule.js +2 -0
- package/lib/module/types/GoogleMobileAdsNativeModule.js.map +1 -0
- package/lib/module/types/MobileAd.interface.js +2 -0
- package/lib/module/types/MobileAd.interface.js.map +1 -0
- package/lib/module/types/MobileAdsModule.interface.js +2 -0
- package/lib/module/types/MobileAdsModule.interface.js.map +1 -0
- package/lib/module/types/Module.interface.js +2 -0
- package/lib/module/types/Module.interface.js.map +1 -0
- package/lib/module/types/RequestConfiguration.js +2 -0
- package/lib/module/types/RequestConfiguration.js.map +1 -0
- package/lib/module/types/RequestOptions.js +2 -0
- package/lib/module/types/RequestOptions.js.map +1 -0
- package/lib/module/types/RewardedAdReward.js +2 -0
- package/lib/module/types/RewardedAdReward.js.map +1 -0
- package/lib/module/validateAdRequestConfiguration.js +60 -0
- package/lib/module/validateAdRequestConfiguration.js.map +1 -0
- package/lib/module/validateAdRequestOptions.js +150 -0
- package/lib/module/validateAdRequestOptions.js.map +1 -0
- package/lib/module/validateAdShowOptions.js +39 -0
- package/lib/module/validateAdShowOptions.js.map +1 -0
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/AdEventType.d.ts +47 -0
- package/lib/typescript/AdsConsent.d.ts +2 -0
- package/lib/typescript/AdsConsentDebugGeography.d.ts +19 -0
- package/lib/typescript/AdsConsentStatus.d.ts +17 -0
- package/lib/typescript/BannerAdSize.d.ts +34 -0
- package/lib/typescript/MaxAdContentRating.d.ts +18 -0
- package/lib/typescript/MobileAds.d.ts +11 -0
- package/lib/typescript/RewardedAdEventType.d.ts +46 -0
- package/lib/typescript/TestIds.d.ts +6 -0
- package/lib/typescript/ads/AppOpenAd.d.ts +11 -0
- package/lib/typescript/ads/BannerAd.d.ts +3 -0
- package/lib/typescript/ads/InterstitialAd.d.ts +78 -0
- package/lib/typescript/ads/MobileAd.d.ts +32 -0
- package/lib/typescript/ads/RewardedAd.d.ts +84 -0
- package/lib/typescript/common/Base64.d.ts +14 -0
- package/lib/typescript/common/MutatableParams.d.ts +9 -0
- package/lib/typescript/common/ReferenceBase.d.ts +11 -0
- package/lib/typescript/common/deeps.d.ts +18 -0
- package/lib/typescript/common/id.d.ts +11 -0
- package/lib/typescript/common/index.d.ts +28 -0
- package/lib/typescript/common/path.d.ts +43 -0
- package/lib/typescript/common/promise.d.ts +13 -0
- package/lib/typescript/common/serialize.d.ts +5 -0
- package/lib/typescript/common/validate.d.ts +90 -0
- package/lib/typescript/index.d.ts +14 -0
- package/lib/typescript/internal/GoogleMobileAdsNativeEventEmitter.d.ts +12 -0
- package/lib/typescript/internal/Module.d.ts +13 -0
- package/lib/typescript/internal/NativeError.d.ts +26 -0
- package/lib/typescript/internal/SharedEventEmitter.d.ts +2 -0
- package/lib/typescript/internal/constants.d.ts +3 -0
- package/lib/typescript/internal/index.d.ts +4 -0
- package/lib/typescript/internal/registry/nativeModule.d.ts +15 -0
- package/lib/typescript/types/AdEventListener.d.ts +11 -0
- package/lib/typescript/types/AdShowOptions.d.ts +12 -0
- package/lib/typescript/types/AdapterStatus.d.ts +18 -0
- package/lib/typescript/types/AdsConsent.interface.d.ts +286 -0
- package/lib/typescript/types/BannerAdProps.d.ts +66 -0
- package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +14 -0
- package/lib/typescript/types/MobileAd.interface.d.ts +64 -0
- package/lib/typescript/types/MobileAdsModule.interface.d.ts +38 -0
- package/lib/typescript/types/Module.interface.d.ts +14 -0
- package/lib/typescript/types/RequestConfiguration.d.ts +36 -0
- package/lib/typescript/types/RequestOptions.d.ts +106 -0
- package/lib/typescript/types/RewardedAdReward.d.ts +13 -0
- package/lib/typescript/validateAdRequestConfiguration.d.ts +2 -0
- package/lib/typescript/validateAdRequestOptions.d.ts +2 -0
- package/lib/typescript/validateAdShowOptions.d.ts +2 -0
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +143 -0
- package/react-native.config.js +19 -0
- package/src/AdEventType.ts +68 -0
- package/src/AdsConsent.ts +191 -0
- package/src/AdsConsentDebugGeography.ts +38 -0
- package/src/AdsConsentStatus.ts +36 -0
- package/src/BannerAdSize.ts +59 -0
- package/src/MaxAdContentRating.ts +38 -0
- package/src/MobileAds.ts +84 -0
- package/src/RewardedAdEventType.ts +64 -0
- package/src/TestIds.ts +39 -0
- package/src/ads/AppOpenAd.ts +85 -0
- package/src/ads/BannerAd.tsx +126 -0
- package/src/ads/InterstitialAd.ts +156 -0
- package/src/ads/MobileAd.ts +101 -0
- package/src/ads/RewardedAd.ts +161 -0
- package/src/common/Base64.ts +114 -0
- package/src/common/MutatableParams.ts +50 -0
- package/src/common/ReferenceBase.ts +45 -0
- package/src/common/deeps.ts +88 -0
- package/src/common/id.ts +74 -0
- package/src/common/index.ts +103 -0
- package/src/common/path.ts +114 -0
- package/src/common/promise.ts +66 -0
- package/src/common/serialize.ts +43 -0
- package/src/common/validate.ts +205 -0
- package/src/declarations.d.ts +3 -0
- package/src/index.ts +35 -0
- package/src/internal/GoogleMobileAdsNativeEventEmitter.ts +81 -0
- package/src/internal/Module.ts +58 -0
- package/src/internal/NativeError.ts +56 -0
- package/src/internal/SharedEventEmitter.ts +22 -0
- package/src/internal/constants.ts +43 -0
- package/src/internal/index.ts +21 -0
- package/src/internal/registry/nativeModule.ts +226 -0
- package/src/types/AdEventListener.ts +16 -0
- package/src/types/AdShowOptions.ts +12 -0
- package/src/types/AdapterStatus.ts +20 -0
- package/src/types/AdsConsent.interface.ts +306 -0
- package/src/types/BannerAdProps.ts +73 -0
- package/src/types/GoogleMobileAdsNativeModule.ts +15 -0
- package/src/types/MobileAd.interface.ts +69 -0
- package/src/types/MobileAdsModule.interface.ts +43 -0
- package/src/types/Module.interface.ts +16 -0
- package/src/types/RequestConfiguration.ts +40 -0
- package/src/types/RequestOptions.ts +113 -0
- package/src/types/RewardedAdReward.ts +14 -0
- package/src/validateAdRequestConfiguration.ts +71 -0
- package/src/validateAdRequestOptions.ts +168 -0
- package/src/validateAdShowOptions.ts +41 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
package io.invertase.googlemobileads.common;
|
|
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 java.util.ArrayList;
|
|
21
|
+
import java.util.HashMap;
|
|
22
|
+
import java.util.List;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
import java.util.concurrent.ExecutorService;
|
|
25
|
+
import java.util.concurrent.Executors;
|
|
26
|
+
import java.util.concurrent.RejectedExecutionHandler;
|
|
27
|
+
import java.util.concurrent.SynchronousQueue;
|
|
28
|
+
import java.util.concurrent.ThreadPoolExecutor;
|
|
29
|
+
import java.util.concurrent.TimeUnit;
|
|
30
|
+
|
|
31
|
+
public class TaskExecutorService {
|
|
32
|
+
private static final String MAXIMUM_POOL_SIZE_KEY = "android_task_executor_maximum_pool_size";
|
|
33
|
+
private static final String KEEP_ALIVE_SECONDS_KEY = "android_task_executor_keep_alive_seconds";
|
|
34
|
+
|
|
35
|
+
private final String name;
|
|
36
|
+
private final int maximumPoolSize;
|
|
37
|
+
private final int keepAliveSeconds;
|
|
38
|
+
private static final Map<String, ExecutorService> executors = new HashMap<>();
|
|
39
|
+
|
|
40
|
+
TaskExecutorService(String name) {
|
|
41
|
+
this.name = name;
|
|
42
|
+
ReactNativeJSON json = ReactNativeJSON.getSharedInstance();
|
|
43
|
+
this.maximumPoolSize = json.getIntValue(MAXIMUM_POOL_SIZE_KEY, 1);
|
|
44
|
+
this.keepAliveSeconds = json.getIntValue(KEEP_ALIVE_SECONDS_KEY, 3);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public ExecutorService getExecutor() {
|
|
48
|
+
boolean isTransactional = maximumPoolSize <= 1;
|
|
49
|
+
return getExecutor(isTransactional, "");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public ExecutorService getTransactionalExecutor() {
|
|
53
|
+
return getExecutor(true, "");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public ExecutorService getTransactionalExecutor(String identifier) {
|
|
57
|
+
String executorIdentifier = maximumPoolSize != 0 ? identifier : "";
|
|
58
|
+
return getExecutor(true, executorIdentifier);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public ExecutorService getExecutor(boolean isTransactional, String identifier) {
|
|
62
|
+
String executorName = getExecutorName(isTransactional, identifier);
|
|
63
|
+
synchronized (executors) {
|
|
64
|
+
ExecutorService existingExecutor = executors.get(executorName);
|
|
65
|
+
if (existingExecutor == null) {
|
|
66
|
+
ExecutorService newExecutor = getNewExecutor(isTransactional);
|
|
67
|
+
executors.put(executorName, newExecutor);
|
|
68
|
+
return newExecutor;
|
|
69
|
+
}
|
|
70
|
+
return existingExecutor;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private ExecutorService getNewExecutor(boolean isTransactional) {
|
|
75
|
+
if (isTransactional) {
|
|
76
|
+
return Executors.newSingleThreadExecutor();
|
|
77
|
+
} else {
|
|
78
|
+
ThreadPoolExecutor threadPoolExecutor =
|
|
79
|
+
new ThreadPoolExecutor(
|
|
80
|
+
0, maximumPoolSize, keepAliveSeconds, TimeUnit.SECONDS, new SynchronousQueue<>());
|
|
81
|
+
threadPoolExecutor.setRejectedExecutionHandler(executeInFallback);
|
|
82
|
+
return threadPoolExecutor;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private final RejectedExecutionHandler executeInFallback =
|
|
87
|
+
(r, executor) -> {
|
|
88
|
+
if (executor.isShutdown() || executor.isTerminated() || executor.isTerminating()) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
ExecutorService fallbackExecutor = getTransactionalExecutor();
|
|
92
|
+
fallbackExecutor.execute(r);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
public String getExecutorName(boolean isTransactional, String identifier) {
|
|
96
|
+
if (isTransactional) {
|
|
97
|
+
return name + "TransactionalExecutor" + identifier;
|
|
98
|
+
}
|
|
99
|
+
return name + "Executor" + identifier;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public void shutdown() {
|
|
103
|
+
synchronized (executors) {
|
|
104
|
+
List<String> existingExecutorNames = new ArrayList<>(executors.keySet());
|
|
105
|
+
for (String executorName : existingExecutorNames) {
|
|
106
|
+
if (!executorName.startsWith(name)) {
|
|
107
|
+
executors.remove(executorName);
|
|
108
|
+
} else {
|
|
109
|
+
removeExecutor(executorName);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public void removeExecutor(String executorName) {
|
|
116
|
+
synchronized (executors) {
|
|
117
|
+
ExecutorService existingExecutor = executors.get(executorName);
|
|
118
|
+
if (existingExecutor != null) {
|
|
119
|
+
existingExecutor.shutdownNow();
|
|
120
|
+
executors.remove(executorName);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package io.invertase.googlemobileads.interfaces;
|
|
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 android.app.Activity;
|
|
21
|
+
import android.content.Context;
|
|
22
|
+
import com.facebook.react.bridge.ReactContext;
|
|
23
|
+
|
|
24
|
+
public interface ContextProvider {
|
|
25
|
+
Activity getActivity();
|
|
26
|
+
|
|
27
|
+
ReactContext getContext();
|
|
28
|
+
|
|
29
|
+
Context getApplicationContext();
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package io.invertase.googlemobileads.interfaces;
|
|
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 com.facebook.react.bridge.WritableMap;
|
|
21
|
+
|
|
22
|
+
public interface NativeError {
|
|
23
|
+
String getErrorCode();
|
|
24
|
+
|
|
25
|
+
String getErrorMessage();
|
|
26
|
+
|
|
27
|
+
WritableMap getUserInfo();
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package io.invertase.googlemobileads.interfaces;
|
|
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 com.facebook.react.bridge.WritableMap;
|
|
21
|
+
|
|
22
|
+
public interface NativeEvent {
|
|
23
|
+
String getEventName();
|
|
24
|
+
|
|
25
|
+
WritableMap getEventBody();
|
|
26
|
+
}
|
package/babel.config.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
test: {
|
|
4
|
+
presets: [
|
|
5
|
+
[
|
|
6
|
+
'@babel/preset-env',
|
|
7
|
+
{
|
|
8
|
+
targets: {
|
|
9
|
+
node: 'current',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
'module:./node_modules/metro-react-native-babel-preset',
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
plugins: [['@babel/plugin-proposal-private-property-in-object', { loose: true }]],
|
|
18
|
+
};
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# Displaying Ads
|
|
2
|
+
|
|
3
|
+
The AdMob package allows you to display three types of adverts; Interstitial, Rewarded & Banner.
|
|
4
|
+
|
|
5
|
+
## App Open Ads
|
|
6
|
+
|
|
7
|
+
App open ads are a special ad format intended for publishers wishing to monetize their app load screens.
|
|
8
|
+
App open ads can be closed by your users at any time. App open ads can be shown when users bring your app to the foreground.
|
|
9
|
+
|
|
10
|
+
App open ads are shown when your application launches or when users bring your application to the foreground.
|
|
11
|
+
To make sure you have an ad ready to display when a user opens your app, you'll want to have a reference to an ad ready to use.
|
|
12
|
+
|
|
13
|
+
That means you must preload a app open ad before you need to show the ad. That way, your app open ad is ready to show the next time the app is opened.
|
|
14
|
+
|
|
15
|
+
To create a new app open ad, call the `createForAdRequest` method from the `AppOpenAd` class. The first argument
|
|
16
|
+
of the method is the "Ad Unit ID". For testing, we can use a Test ID, however for production the ID from the
|
|
17
|
+
Google AdMob dashboard under "Ad units" should be used:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { AppOpenAd, TestIds, AdEventType } from 'react-native-google-mobile-ads';
|
|
21
|
+
|
|
22
|
+
const adUnitId = __DEV__ ? TestIds.APP_OPEN : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
|
|
23
|
+
|
|
24
|
+
const appOpenAd = AppOpenAd.createForAdRequest(adUnitId, {
|
|
25
|
+
requestNonPersonalizedAdsOnly: true,
|
|
26
|
+
keywords: ['fashion', 'clothing'],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Preload an app open ad
|
|
30
|
+
appOpenAd.load()
|
|
31
|
+
|
|
32
|
+
// Show the app open ad when user brings the app to the foreground.
|
|
33
|
+
appOpenAd.show()
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Consider ad expiration
|
|
38
|
+
|
|
39
|
+
Key Point: Ad references in the app open beta will time out after four hours.
|
|
40
|
+
Ads rendered more than four hours after request time will no longer be valid and may not earn revenue.
|
|
41
|
+
This time limit is being carefully considered and may change in future beta versions of the app open format.
|
|
42
|
+
|
|
43
|
+
### Cold starts and loading screens
|
|
44
|
+
|
|
45
|
+
The above documentation assumes that you only show app open ads when users foreground your app when it is suspended in memory.
|
|
46
|
+
"Cold starts" occur when your app is launched but was not previously suspended in memory.
|
|
47
|
+
|
|
48
|
+
An example of a cold start is when a user opens your app for the first time.
|
|
49
|
+
With cold starts, you won't have a previously loaded app open ad that's ready to be shown right away.
|
|
50
|
+
The delay between when you request an ad and receive an ad back can create a situation where users are able to briefly use your app before being surprised by an out of context ad.
|
|
51
|
+
This should be avoided because it is a bad user experience.
|
|
52
|
+
|
|
53
|
+
The preferred way to use app open ads on cold starts is to use a loading screen to load your game or app assets, and to only show the ad from the loading screen.
|
|
54
|
+
If your app has completed loading and has sent the user to the main content of your app, do not show the ad.
|
|
55
|
+
|
|
56
|
+
### Best practices
|
|
57
|
+
|
|
58
|
+
Google built app open ads to help you monetize your app's loading screen, but it's important to keep best practices in mind so that your users enjoy using your app. Make sure to:
|
|
59
|
+
|
|
60
|
+
- Wait to show your first app open ad until after your users have used your app a few times.
|
|
61
|
+
- Show app open ads during times when your users would otherwise be waiting for your app to load.
|
|
62
|
+
- If you have a loading screen under the app open ad, and your loading screen completes loading before the ad is dismissed, you may want to dismiss your loading screen after receiving the `onAdClosed` event.
|
|
63
|
+
|
|
64
|
+
## Interstitial Ads
|
|
65
|
+
|
|
66
|
+
Interstitials are full-screen ads that cover the interface of an app until closed by the user. These type of ads are
|
|
67
|
+
programmatically loaded and then shown at a suitable point during your application flow (e.g. after a level on a gaming
|
|
68
|
+
app has been completed, or game over). The ads can be preloaded in the background to ensure they're ready to go when needed.
|
|
69
|
+
|
|
70
|
+
To create a new interstitial, call the `createForAdRequest` method from the `InterstitialAd` class. The first argument
|
|
71
|
+
of the method is the "Ad Unit ID". For testing, we can use a Test ID, however for production the ID from the
|
|
72
|
+
Google AdMob dashboard under "Ad units" should be used:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
import { InterstitialAd, TestIds, AdEventType } from 'react-native-google-mobile-ads';
|
|
76
|
+
|
|
77
|
+
const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
|
|
78
|
+
|
|
79
|
+
const interstitial = InterstitialAd.createForAdRequest(adUnitId, {
|
|
80
|
+
requestNonPersonalizedAdsOnly: true,
|
|
81
|
+
keywords: ['fashion', 'clothing'],
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The second argument is additional optional request options object to be sent whilst loading an advert, such as keywords & location.
|
|
86
|
+
Setting additional request options helps AdMob choose better tailored ads from the network. View the [`RequestOptions`](/reference/admob/requestoptions)
|
|
87
|
+
documentation to view the full range of options available.
|
|
88
|
+
|
|
89
|
+
The call to `createForAdRequest` returns an instance of the [`InterstitialAd`](/reference/admob/interstitialad) class,
|
|
90
|
+
which provides a number of utilities for loading and displaying interstitials.
|
|
91
|
+
|
|
92
|
+
To listen to events, such as when the advert from the network has loaded or when an error occurs, we can subscribe via the
|
|
93
|
+
`onAdEvent` method:
|
|
94
|
+
|
|
95
|
+
```jsx
|
|
96
|
+
import React, { useEffect, useState } from 'react';
|
|
97
|
+
import { Button } from 'react-native';
|
|
98
|
+
import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';
|
|
99
|
+
|
|
100
|
+
const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
|
|
101
|
+
|
|
102
|
+
const interstitial = InterstitialAd.createForAdRequest(adUnitId, {
|
|
103
|
+
requestNonPersonalizedAdsOnly: true,
|
|
104
|
+
keywords: ['fashion', 'clothing'],
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function App() {
|
|
108
|
+
const [loaded, setLoaded] = useState(false);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const eventListener = interstitial.onAdEvent(type => {
|
|
112
|
+
if (type === AdEventType.LOADED) {
|
|
113
|
+
setLoaded(true);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Start loading the interstitial straight away
|
|
118
|
+
interstitial.load();
|
|
119
|
+
|
|
120
|
+
// Unsubscribe from events on unmount
|
|
121
|
+
return () => {
|
|
122
|
+
eventListener();
|
|
123
|
+
};
|
|
124
|
+
}, []);
|
|
125
|
+
|
|
126
|
+
// No advert ready to show yet
|
|
127
|
+
if (!loaded) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<Button
|
|
133
|
+
title="Show Interstitial"
|
|
134
|
+
onPress={() => {
|
|
135
|
+
interstitial.show();
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The code above subscribes to the interstitial events (via `onAdEvent()`) and immediately starts to load a new advert from
|
|
143
|
+
the network (via `load()`). Once an advert is available, local state is set, re-rendering the component showing a `Button`.
|
|
144
|
+
When pressed, the `show` method on the interstitial instance is called and the advert is shown over-the-top of your
|
|
145
|
+
application.
|
|
146
|
+
|
|
147
|
+
The `onAdEvent` listener also triggers when events inside of the application occur, such as if the user clicks the advert,
|
|
148
|
+
or closes the advert and returns back to your app. To view a full list of events which are available, view the
|
|
149
|
+
[`AdEventType`](/reference/admob/adeventtype) documentation.
|
|
150
|
+
|
|
151
|
+
If needed, you can reuse the existing instance of the `InterstitialAd` class to load more adverts and show them when required.
|
|
152
|
+
|
|
153
|
+
## Rewarded Ads
|
|
154
|
+
|
|
155
|
+
Rewarded Ads are full-screen ads that cover the interface of an app until closed by the user. The content of a rewarded
|
|
156
|
+
advert is controlled via the Google AdMob dashboard.
|
|
157
|
+
|
|
158
|
+
The purpose of a rewarded ad is to reward users with _something_ after completing an action inside of the advert, such
|
|
159
|
+
as watching a video or submitting an option via an interactive form. If the user completes the action, you can reward them
|
|
160
|
+
with something (e.g. in-game currency).
|
|
161
|
+
|
|
162
|
+
To create a new interstitial, call the `createForAdRequest` method from the `RewardedAd` class. The first argument
|
|
163
|
+
of the method is the "Ad Unit ID". For testing, we can use a Test ID, however for production the ID from the
|
|
164
|
+
Google AdMob dashboard under "Ad units" should be used:
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
import { RewardedAd, TestIds } from 'react-native-google-mobile-ads';
|
|
168
|
+
|
|
169
|
+
const adUnitId = __DEV__ ? TestIds.REWARDED : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
|
|
170
|
+
|
|
171
|
+
const rewarded = RewardedAd.createForAdRequest(adUnitId, {
|
|
172
|
+
requestNonPersonalizedAdsOnly: true,
|
|
173
|
+
keywords: ['fashion', 'clothing'],
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The second argument is additional optional request options object to be sent whilst loading an advert, such as keywords & location.
|
|
178
|
+
Setting additional request options helps AdMob choose better tailored ads from the network. View the [`RequestOptions`](/reference/admob/requestoptions)
|
|
179
|
+
documentation to view the full range of options available.
|
|
180
|
+
|
|
181
|
+
The call to `createForAdRequest` returns an instance of the [`RewardedAd`](/reference/admob/rewardedad) class,
|
|
182
|
+
which provides a number of utilities for loading and displaying rewarded ads.
|
|
183
|
+
|
|
184
|
+
To listen to events, such as when the advert from the network has loaded or when an error occurs, we can subscribe via the
|
|
185
|
+
`onAdEvent` method:
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
import React, { useEffect, useState } from 'react';
|
|
189
|
+
import { Button } from 'react-native';
|
|
190
|
+
import { RewardedAd, RewardedAdEventType, TestIds } from 'react-native-google-mobile-ads';
|
|
191
|
+
|
|
192
|
+
const adUnitId = __DEV__ ? TestIds.REWARDED : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
|
|
193
|
+
|
|
194
|
+
const rewarded = RewardedAd.createForAdRequest(adUnitId, {
|
|
195
|
+
requestNonPersonalizedAdsOnly: true,
|
|
196
|
+
keywords: ['fashion', 'clothing'],
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
function App() {
|
|
200
|
+
const [loaded, setLoaded] = useState(false);
|
|
201
|
+
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
const eventListener = rewarded.onAdEvent((type, error, reward) => {
|
|
204
|
+
if (type === RewardedAdEventType.LOADED) {
|
|
205
|
+
setLoaded(true);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (type === RewardedAdEventType.EARNED_REWARD) {
|
|
209
|
+
console.log('User earned reward of ', reward);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Start loading the rewarded ad straight away
|
|
214
|
+
rewarded.load();
|
|
215
|
+
|
|
216
|
+
// Unsubscribe from events on unmount
|
|
217
|
+
return () => {
|
|
218
|
+
eventListener();
|
|
219
|
+
};
|
|
220
|
+
}, []);
|
|
221
|
+
|
|
222
|
+
// No advert ready to show yet
|
|
223
|
+
if (!loaded) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<Button
|
|
229
|
+
title="Show Rewarded Ad"
|
|
230
|
+
onPress={() => {
|
|
231
|
+
rewarded.show();
|
|
232
|
+
}}
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
The code above subscribes to the rewarded ad events (via `onAdEvent()`) and immediately starts to load a new advert from
|
|
239
|
+
the network (via `load()`). Once an advert is available, local state is set, re-rendering the component showing a `Button`.
|
|
240
|
+
When pressed, the `show` method on the rewarded ad instance is called and the advert is shown over-the-top of your
|
|
241
|
+
application.
|
|
242
|
+
|
|
243
|
+
Like Interstitial Ads, the events returns from the `onAdEvent` listener trigger when the user clicks the advert or closes
|
|
244
|
+
the advert and returns back to your app. However, an extra `EARNED_REWARD` event can be triggered if the user completes the
|
|
245
|
+
advert action. An additional `reward` property is sent with the event, containing the amount and type of rewarded (specified via the dashboard).
|
|
246
|
+
An additional `reward` property is sent with the event, containing the amount and type of rewarded (specified via the dashboard).
|
|
247
|
+
|
|
248
|
+
To learn more, view the [`RewardedAdEventType`](/reference/admob/rewardedadeventtype) documentation.
|
|
249
|
+
|
|
250
|
+
If needed, you can reuse the existing instance of the `RewardedAd` class to load more adverts and show them when required.
|
|
251
|
+
|
|
252
|
+
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.
|
|
253
|
+
|
|
254
|
+
You can customize SSV parameters when your SSV callback is called by setting the `serverSideVerificationOptions` field in your [`RequestOptions`](/reference/admob/requestoptions) parameter.
|
|
255
|
+
|
|
256
|
+
```js
|
|
257
|
+
const rewardedAd = RewardedAd.createForAdRequest(adUnitId, {
|
|
258
|
+
serverSideVerificationOptions: {
|
|
259
|
+
userId: '9999',
|
|
260
|
+
customData: 'my-custom-data',
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
If you request an Advert as in the example above, AdMob will call your server with the `userId` and `customData` fields as shown below:
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
[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
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
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).
|
|
272
|
+
|
|
273
|
+
## Banner Ads
|
|
274
|
+
|
|
275
|
+
Banner ads are partial adverts which can be integrated within your existing application. Unlike Interstitial and Rewarded Ads,
|
|
276
|
+
a Banner only takes up a limited area of the application and displays an advert within the area. This allows you to integrate
|
|
277
|
+
adverts without a disruptive action.
|
|
278
|
+
|
|
279
|
+
The module exposes a [`BannerAd`](/reference/admob/bannerad) component. The `unitId` and `size` props are required to display
|
|
280
|
+
a banner:
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
import React from 'react';
|
|
284
|
+
import { BannerAd, BannerAdSize, TestIds } from 'react-native-google-mobile-ads';
|
|
285
|
+
|
|
286
|
+
const adUnitId = __DEV__ ? TestIds.BANNER : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
|
|
287
|
+
|
|
288
|
+
function App() {
|
|
289
|
+
return (
|
|
290
|
+
<BannerAd
|
|
291
|
+
unitId={adUnitId}
|
|
292
|
+
size={BannerAdSize.FULL_BANNER}
|
|
293
|
+
requestOptions={{
|
|
294
|
+
requestNonPersonalizedAdsOnly: true,
|
|
295
|
+
}}
|
|
296
|
+
/>
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
The `size` prop takes a [`BannerAdSize`](/reference/admob/banneradsize) type, and once the advert is available, will
|
|
302
|
+
fill the space for the chosen size.
|
|
303
|
+
|
|
304
|
+
> If no inventory for the size specified is available, an error will be thrown via `onAdFailedToLoad`!
|
|
305
|
+
|
|
306
|
+
The `requestOptions` prop is additional optional request options object to be sent whilst loading an advert, such as keywords & location.
|
|
307
|
+
Setting additional request options helps AdMob choose better tailored ads from the network. View the [`RequestOptions`](/reference/admob/requestoptions)
|
|
308
|
+
documentation to view the full range of options available.
|
|
309
|
+
|
|
310
|
+
The component also exposes props for listening to events, which you can use to handle the state of your app is the user
|
|
311
|
+
or network triggers an event:
|
|
312
|
+
|
|
313
|
+
- `onAdClosed`
|
|
314
|
+
- `onAdFailedToLoad`
|
|
315
|
+
- `onAdLeftApplication`
|
|
316
|
+
- `onAdOpened`
|
|
317
|
+
|
|
318
|
+
Each render of the component loads a single advert, allowing you to display multiple adverts at once. If you need to reload/change
|
|
319
|
+
an advert for a currently mounted component, you'll need to force a re-render inside of your own code.
|