npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bamlab-react-native-admob

v1.4.0

Published

A react-native component for Google AdMob banners and interstitials

Downloads

6

Readme

npm version

react-native-admob

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.

Installation

Automatic Installation (recommended)

  1. npm i react-native-admob -S
  2. react-native link
  3. Add the Google Mobile Ads SDK to your Xcode project with CocoaPods or manually. This is only needed for iOS and guarantees your app is using the newest AdMob version.

Manual Installation

iOS
  1. npm i react-native-admob -S
  2. Add the Google Mobile Ads SDK to your Xcode project with CocoaPods or manually. This is only needed for iOS and guarantees your app is using the newest AdMob version.
  3. Add react-native-admob static library to your Xcode project like explained here. (Step 3 of this guide is not needed)
Android
  1. npm i react-native-admob -S
  2. Make the following additions to the given files:

android/settings.gradle

include ':RNAdMob', ':app'
project(':RNAdMob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')

android/app/build.gradle

dependencies {
   ...
   compile project(':RNAdMob')
}

MainApplication.java

RN < 0.29

In MainActivity.java on top, where imports are:

import com.sbugert.rnadmob.RNAdMobPackage;

Under protected List<ReactPackage> getPackages() {:

  return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new RNAdMobPackage()
  );

RN >= 0.29

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()
  );

Usage

import { 
  AdMobBanner, 
  AdMobInterstitial, 
  PublisherBanner,
  AdMobRewarded
} from 'react-native-admob'

// Display a banner
<AdMobBanner
  bannerSize="fullBanner"
  adUnitID="your-admob-unit-id"
  testDeviceID="EMULATOR"
  didFailToReceiveAdWithError={this.bannerError} />

// Display a DFP Publisher banner
<PublisherBanner
  bannerSize="fullBanner"
  adUnitID="your-admob-unit-id"
  testDeviceID="EMULATOR"
  didFailToReceiveAdWithError={this.bannerError}
  admobDispatchAppEvent={this.adMobEvent} />

// Display an interstitial
AdMobInterstitial.setAdUnitID('your-admob-unit-id');
AdMobInterstitial.setTestDeviceID('EMULATOR');
AdMobInterstitial.requestAd(AdMobInterstitial.showAd);

// Display a rewarded ad
AdMobRewarded.setAdUnitID('your-admob-unit-id');
AdMobRewarded.requestAd(AdMobRewarded.showAd);

For a full example reference to the example project.

Reference

AdMobBanner

bannerSize property

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|50|90| |smartBannerLandscape |Smart Banner for 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

Events as function props

Corresponding to Ad lifecycle event callbacks

| Prop | |------------------------------------------------| |adViewDidReceiveAd() | |didFailToReceiveAdWithError(errorDescription) | |adViewWillPresentScreen() | |adViewWillDismissScreen() | |adViewDidDismissScreen() | |adViewWillLeaveApplication() |

PublisherBanner

Same as AdMobBanner, except it has an extra event prop:

|'admobDispatchAppEvent()' |

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/android/banner#ios_app-events

AdMobInterstitials

Methods

| Name | Description | |---------------------------|-----------------------------------------------------------------------------------------------------------------| |setAdUnitID(adUnitID) | sets the AdUnit ID for all future ad requests. | |setTestDeviceID(deviceID)| sets the test device ID | |requestAd(callback) | requests an interstitial and calls callback when interstitialDidLoad orinterstitialDidFailToLoad event fires| |showAd(callback) | shows an interstitial if it is ready and calls callback when interstitialDidOpen event fires | |isReady(callback) | calls callback with boolean whether interstitial is ready to be shown |

For simulators/emulators you can use 'EMULATOR' for the test device ID.
Note: tryShowNewInterstitial() is deprecated as of v1.1.0 and can be replaced by calling requestAd with showAd as callback.

Events

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.

AdMobRewarded

Opens a rewarded AdMob ad.

Methods

| Name | Description | |---------------------------|-----------------------------------------------------------------------------------------------------------------| |setAdUnitID(adUnitID) | sets the AdUnit ID for all future ad requests. | |setTestDeviceID(deviceID)| sets the test device ID | |requestAd(callback) | requests a rewarded ad| |showAd(callback) | shows a rewarded if it is ready |

Events

| iOS | this library | Android | |--------------------------------------------|-----------------------------------|----------------------------------| |rewardBasedVideoAd:didRewardUserWithReward|rewardedVideoDidRewardUser |onRewarded | |rewardBasedVideoAdDidReceiveAd |rewardedVideoDidLoad |onRewardedVideoAdLoaded | |rewardBasedVideoAd:didFailToLoadWithError |rewardedVideoDidFailToLoad |onRewardedVideoAdFailedToLoad | |rewardBasedVideoAdDidOpen |rewardedVideoDidOpen |onRewardedVideoAdOpened | |rewardBasedVideoAdDidClose |rewardedVideoDidClose |onRewardedVideoAdClosed | |rewardBasedVideoAdWillLeaveApplication |rewardedVideoWillLeaveApplication|onRewardedVideoAdLeftApplication|


TODO

  • [ ] Support Ad Targeting
  • [ ] Also use interstitial event names for banner
  • [ ] PublisherBanner [DFPBanner/PublisherAdView should be able to accept multiple adSizes. Currently only caters for a single size]