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

@callosum/react-native-google-ad-manager

v2.0.2

Published

Google Ad Manager for react-native

Downloads

83

Readme

react-native-google-ad-manager

This library integrates Banners for Google Ad Manager. To create issues and PRs please refer to the main repository here.

Getting started

For React Native versions < 0.60 use version 0.+ of this library and checkout the corresponding README file.

$ npm install @callosum/react-native-google-ad-manager --save

Integration

Learn how to set up GAM for your app.

iOS

Swift

  • Under Build Settings section Build Options set Always Embed Swift Started Libraries to true

GAM

  • Activate as Ad Manager app by editing your Info.plist
...
+ <key>GADIsAdManagerApp</key>
+ <true/>
...
  • Add transport security rules in Info.plist
...
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsForMedia</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>
...

Android

  • Activate as Ad Manager app
<manifest>
  <application>
    ...
+   <meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true"/>
    ...
  </application>
</manifest>

Usage

Automatic Banner

This banner component automatically fetches an ad and adds the view when the ad is sucessfully loaded. It also takes care of the cleanup on unmount.

Props

type GAMAutomaticBanner = {
  adId: String,
  onAdFailedToLoad: function<error>,
  onAdLoaded: function<object: { height, width }>,
  onAdRequest: function<>,
  adSizes: Array<Array<width, height>>,
  testDeviceIds: Array<string>,
  style: styles,
}

Example

import { GAMAutomaticBanner } from '@callosum/react-native-google-ad-manager';

const AdBanner = () => (
  <GAMAutomaticBanner
    adId="/6499/example/banner"
    adSizes={[[320, 50]]}
    testDeviceIds={[RNGAMBanner.simulatorTestId]}
    style={{ height: 50, width: 320 }}
  />
)

Banner

This is a banner component that gives your more access to pure functionality in order to implement dynamic solutions like lazy loading and more performant integrations for repeating units in lists. It implements the same props as the automatic banner.

Additionally, you have the following methos available:

loadBanner()

This loads an ad but does not add it to the view hierarchy.

destroyBanner()

This destroys the created / loaded ad.

addBannerView()

This adds the native view to the view hierarchy.

removeBannerView()

This removes the native view from the view hierarchy.

Example

import { useRef } from "react";
import { RNGAMBanner } from "@callosum/react-native-google-ad-manager";

const AdBanner = () => {
  const _ref = useRef(null);

  useEffect(() => {
    _ref.current.loadBanner()

    return () => {
      _ref.current.removeBannerView()
      _ref.current.destroyBanner()
    }
  }, [])

  return (
    <RNGAMBanner
      adId="/6499/example/banner"
      adSizes={[[300, 250]]}
      testDeviceIds={[RNGAMBanner.simulatorTestId]}
      onAdLoaded={({ height, width }) => {
        _ref.current.addBannerView()
      }}
      onAdFailedToLoad={error => {
        console.log(error)
      }}
      ref={_ref}
      style={{ height: 300, width: 250 }}
    />
  );
};

API

Constants

| Key | Values | |---|---| | simulatorTestId | platform specific simulator id | | sizes | BANNER, MEDIUM_RECTANGLE |