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

@anvilapp/react-native-admob

v1.0.0

Published

A react-native component for Google AdMob banners and interstitials

Downloads

5

Readme

react-native-admob

A react-native module for Google AdMob Banners, Interstitials, and Rewarded Videos, and also DFP Banners.

The banner types are implemented as components while the interstitial and rewarded video have an imperative API.

Installation

You can use npm or Yarn to install the latest beta version:

npm:

npm i --save anvilapp@react-native-admob

Yarn:

yarn add anvilapp@react-native-admob

In order to use this library, you have to link it to your project first. There's excellent documentation on how to do this in the React Native Docs.

iOS

For iOS you will have to add the Google Mobile Ads SDK to your Xcode project.

Android

On Android the AdMob library code is part of Play Services, which is automatically added when this library is linked.

Usage

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.

Reference

AdMobBanner

Properties

adSize

Corresponding to iOS framework banner size constants

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

PublisherBanner

Properties

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.

AdMobInterstitial

In comparison to the AdMobBanner and PublisherBanner which have a declaritive API, the AdMobInterstitial has an imperative API.

Methods

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.

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.

AdMobRewarded

In comparison to the AdMobBanner and PublisherBanner which have a declaritive API, the AdMobRewarded has an imperative API, just like the AdMobInterstitial.

Methods

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.

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.