Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
react-native-admob
Advanced tools
A react-native component for Google AdMob banners and interstitials
A react-native module for Google AdMob GADBanner, DFPBanner and GADInterstitial (react-native v0.19.0 or newer required).
The banner is implemented as a component while the interstitial has an imperative API.
npm i react-native-admob -S
react-native link
npm i react-native-admob -S
npm i react-native-admob -S
android/settings.gradle
include ':react-native-admob'
project(':react-native-admob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')
android/app/build.gradle
dependencies {
// ...
compile project(':react-native-admob')
}
MainApplication.java
In MainAplication.java on top, where imports are:
import com.sbugert.rnadmob.RNAdMobPackage;
Under protected List<ReactPackage> getPackages() {
:
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNAdMobPackage()
);
import {
AdMobBanner,
AdMobInterstitial,
PublisherBanner,
AdMobRewarded,
} from 'react-native-admob'
// Display a banner
<AdMobBanner
adSize="fullBanner"
adUnitID="your-admob-unit-id"
testDevices={[AdMobBanner.simulatorId]}
onDidFailToReceiveAdWithError={error => console.error(error)}
/>
// Display a DFP Publisher banner
<PublisherBanner
adSize="fullBanner"
adUnitID="your-admob-unit-id"
testDevices={[PublisherBanner.simulatorId]}
onDidFailToReceiveAdWithError={error => console.error(error)}
onAdmobDispatchAppEvent={event => console.log(event.name, event.info)}
/>
// Display an interstitial
AdMobInterstitial.setAdUnitID('your-admob-unit-id');
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
// Display a rewarded ad
AdMobRewarded.setAdUnitID('your-admob-unit-id');
AdMobRewarded.requestAd().then(() => AdMobRewarded.showAd());
For a full example reference to the example project.
Corresponding to iOS framework banner size constants
Prop value | Description | Size |
---|---|---|
banner | Standard Banner for Phones and Tablets | 320x50 |
largeBanner | Large Banner for Phones and Tablets | 320x100 |
mediumRectangle | IAB Medium Rectangle for Phones and Tablets | 300x250 |
fullBanner | IAB Full-Size Banner for Tablet | 468x60 |
leaderboard | IAB Leaderboard for Tablets | 728x90 |
smartBannerPortrait | Smart Banner for Phones and Tablets (default) | Screen width x 32 |
smartBannerLandscape | Smart Banner for Phones and Tablets | Screen width x 32 |
Note: There is no smartBannerPortrait
and smartBannerLandscape
on Android. Both prop values will map to smartBanner
Corresponding to Ad lifecycle event callbacks
Prop |
---|
onAdViewDidReceiveAd() |
onDidFailToReceiveAdWithError(error) |
onAdViewWillPresentScreen() |
onAdViewWillDismissScreen() |
onAdViewDidDismissScreen() |
onAdViewWillLeaveApplication() |
Same as AdMobBanner, except it has an extra event prop:
| Prop | |
|onAdmobDispatchAppEvent(event)
| Event has a name
and info
property |
This handles App events that AdMob/DFP can send back to the app. More info here: https://developers.google.com/mobile-ads-sdk/docs/dfp/ios/banner#app_events
And also has an additional validAdSizes
property, which accepts an array of ad sizes which may be eligible to be served.
Name | Description |
---|---|
setAdUnitID(adUnitID) | sets the AdUnit ID for all future ad requests. |
setTestDevices(devices) | sets the devices which are served test ads |
requestAd() | requests an interstitial and returns a promise, which resolves on load and rejects on error |
showAd() | shows an interstitial and returns a promise, which resolves when ready and otherwise rejects |
isReady(callback) | calls callback with boolean whether interstitial is ready to be shown |
For simulators/emulators you can use AdMobInterstitial.simulatorId
for the test device ID.
Unfortunately, events are not consistent across iOS and Android. To have one unified API, new event names are introduced for pairs that are roughly equivalent.
iOS | this library | Android |
---|---|---|
interstitialDidReceiveAd | interstitialDidLoad | onAdLoaded |
interstitial:didFailToReceiveAdWithError | interstitialDidFailToLoad | onAdFailedToLoad |
interstitialWillPresentScreen | interstitialDidOpen | onAdOpened |
interstitialDidFailToPresentScreen | ||
interstitialWillDismissScreen | ||
interstitialDidDismissScreen | interstitialDidClose | onAdClosed |
interstitialWillLeaveApplication | interstitialWillLeaveApplication | onAdLeftApplication |
Note that interstitialWillLeaveApplication
and onAdLeftApplication
are not exactly the same but share one event in this library.
Opens a rewarded AdMob ad.
Name | Description |
---|---|
setAdUnitID(adUnitID) | sets the AdUnit ID for all future ad requests |
setTestDevices(devices) | sets the devices which are served test ads |
requestAd() | requests an rewarded ad and returns a promise, which resolves on load and rejects on error |
showAd() | shows an rewarded ad and returns a promise, which resolves when ready and otherwise rejects |
isReady(callback) | calls callback with boolean whether interstitial is ready to be shown |
iOS | this library | Android |
---|---|---|
rewardBasedVideoAd:didRewardUserWithReward | rewardedVideoDidRewardUser | onRewarded |
rewardBasedVideoAdDidReceiveAd | rewardedVideoDidLoad | onRewardedVideoAdLoaded |
rewardBasedVideoAd:didFailToLoadWithError | rewardedVideoDidFailToLoad | onRewardedVideoAdFailedToLoad |
rewardBasedVideoAdDidOpen | rewardedVideoDidOpen | onRewardedVideoAdOpened |
rewardBasedVideoAdDidClose | rewardedVideoDidClose | onRewardedVideoAdClosed |
rewardBasedVideoAdWillLeaveApplication | rewardedVideoWillLeaveApplication | onRewardedVideoAdLeftApplication |
FAQs
A react-native component for Google AdMob banners and interstitials
The npm package react-native-admob receives a total of 69 weekly downloads. As such, react-native-admob popularity was classified as not popular.
We found that react-native-admob demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.