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 react-native-admob
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]}
onAdFailedToLoad={error => console.error(error)}
/>
// Display a DFP Publisher banner
<PublisherBanner
adSize="fullBanner"
adUnitID="your-admob-unit-id"
testDevices={[PublisherBanner.simulatorId]}
onAdFailedToLoad={error => console.error(error)}
onAppEvent={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.
adSize
Corresponding to iOS framework banner size constants
Value | Description | Availability | Size (WxH) |
---|---|---|---|
banner | Standard Banner | Phones and Tablets | 320x50 |
largeBanner | Large Banner | Phones and Tablets | 320x100 |
mediumRectangle | IAB Medium Rectangle | Phones and Tablets | 300x250 |
fullBanner | IAB Full-Size Banner | Tablets | 468x60 |
leaderboard | IAB Leaderboard | Tablets | 728x90 |
smartBannerPortrait smartBannerLandscape
| Smart Banner | Phones and Tablets | Screen width x 32|50|90 |
Note: There is no smartBannerPortrait
and smartBannerLandscape
on Android. Both prop values will map to smartBanner
onAdLoaded
Accepts a function. Called when an ad is received.
onAdFailedToLoad
Accepts a function. Called when an ad request failed.
onAdOpened
Accepts a function. Called when an ad opens an overlay that covers the screen.
onAdClosed
Accepts a function. Called when the user is about to return to the application after clicking on an ad.
onAdLeftApplication
Accepts a function. Called when a user click will open another app (such as the App Store), backgrounding the current app.
onSizeChange
Accepts a function. Called when the size of the banner changes. The function is called with an object containing the width and the height.
Above names correspond to the Ad lifecycle event callbacks
Same as AdMobBanner
, with the addition of 2 extra properties:
onAppEvent
Accepts a function. Called when DFP sends an event back to the app.
These events may occur at any time during the ad's lifecycle, even before onAdLoaded
is called. The function is called with an object, containing the name of the event and an info property, containing additional information.
More info here: https://developers.google.com/mobile-ads-sdk/docs/dfp/ios/banner#app_events
validAdSizes
An array of ad sizes which may be eligible to be served.
In comparison to the AdMobBanner
and PublisherBanner
which have a declaritive API, the AdMobInterstitial
has an imperative API.
setAdUnitID(adUnitID)
Sets the AdUnit ID for all future ad requests.
setTestDevices(devices)
Sets the devices which are served test ads.
For simulators/emulators you can use AdMobInterstitial.simulatorId
for the test device ID.
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 an ad is going to be shown, rejects when the ad is not ready to be shown.
isReady(callback)
Calls callback with a boolean value whether the interstitial is ready to be shown.
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.
This library | iOS | Android |
---|---|---|
adLoaded | interstitialDidReceiveAd | onAdLoaded |
adFailedToLoad | interstitial:didFailToReceiveAdWithError | onAdFailedToLoad |
adOpened | interstitialWillPresentScreen | onAdOpened |
adFailedToOpen | interstitialDidFailToPresentScreen | Not supported |
adClosed | interstitialWillDismissScreen | onAdClosed |
adLeftApplication | interstitialWillLeaveApplication | onAdLeftApplication |
In comparison to the AdMobBanner
and PublisherBanner
which have a declaritive API, the AdMobRewarded
has an imperative API, just like the AdMobInterstitial
.
setAdUnitID(adUnitID)
Sets the AdUnit ID for all future ad requests.
setTestDevices(devices)
Sets the devices which are served test ads.
For simulators/emulators you can use AdMobRewarded.simulatorId
for the test device ID.
requestAd()
Requests a rewarded ad and returns a promise, which resolves on load and rejects on error.
showAd()
Shows a rewarded ad and returns a promise, which resolves when an ad is going to be shown, rejects when the ad is not ready to be shown.
isReady(callback)
Calls callback with a boolean value whether the rewarded ad is ready to be shown.
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.
This library | iOS | Android |
---|---|---|
adLoaded | rewardBasedVideoAdDidReceiveAd | onRewardedVideoAdLoaded |
adFailedToLoad | rewardBasedVideoAd:didFailToLoadWithError | onRewardedVideoAdFailedToLoad |
rewarded | rewardBasedVideoAd:didRewardUserWithReward | onRewarded |
adOpened | rewardBasedVideoAdDidOpen | onRewardedVideoAdOpened |
videoStarted | rewardBasedVideoAdDidStartPlaying | onRewardedVideoStarted |
adClosed | rewardBasedVideoAdDidClose | onRewardedVideoAdClosed |
adLeftApplication | rewardBasedVideoAdWillLeaveApplication | onRewardedVideoAdLeftApplication |
FAQs
A react-native component for Google AdMob banners and interstitials
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.