@freddixx/react-native-ad-manager

中文文档
1.4.6发布于 2022/04/12MITCommonJS近 30 天下载 1.6万

A react-native component for Google Ad Manager banners, interstitials and native ads.

原始使用文档
文档目录6 节
  1. Installation
  2. Getting started
  3. Mostly automatic installation
  4. iOS
  5. Android
  6. Usage

react-native-ad-manager

A react-native module for Google Ad Manager Banners, Interstitials and Native ads.

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

Native ads are implemented as wrapper for a native view.

Installation

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

Getting started

npm:

npm i --save @freddixx/react-native-ad-manager

Yarn:

yarn add @freddixx/react-native-ad-manager

Mostly automatic installation

$ react-native link @freddixx/react-native-ad-manager

Alternatively for iOS you can install the library with CocoaPods by adding a line to your Podfile;

pod 'react-native-ad-manager', path: '../node_modules/@freddixx/react-native-ad-manager'

iOS

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

Android

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

But you still have to manually update your AndroidManifest.xml, as described in the Google Mobile Ads SDK documentation.

Usage

import {
  Banner,
  Interstitial,
  PublisherBanner,
  NativeAdsManager,
} from "@freddixx/react-native-ad-manager";

// Display a DFP Publisher banner
<Banner
  adSize="fullBanner"
  adUnitID="your-ad-unit-id"
  testDevices={[PublisherBanner.simulatorId]}
  onAdFailedToLoad={(error) => console.error(error)}
  onAppEvent={(event) => console.log(event.name, event.info)}
/>;

// Display an interstitial
Interstitial.setAdUnitID("your-ad-unit-id");
Interstitial.setTestDevices([Interstitial.simulatorId]);
Interstitial.requestAd().then(() => Interstitial.showAd());

// Native ad
import NativeAdView from "./NativeAdView";
const adsManager = new NativeAdsManager("your-ad-unit-id", [
  Interstitial.simulatorId,
]);
<NativeAdView
  targeting={{
    customTargeting: { group: "user_test" },
    categoryExclusions: ["media"],
    contentURL: "test://",
    publisherProvidedID: "provider_id",
  }}
  style={{ width: "100%" }}
  adsManager={adsManager}
  validAdTypes={["native", "template"]}
  customTemplateIds={["your-template-id-1", "your-template-id-2"]}
  onAdLoaded={(ad) => {
    console.log(ad);
  }}
  onAdFailedToLoad={(error) => {
    console.log(error);
  }}
/>;

版本与发布记录

@freddixx/react-native-ad-manager 共发布 8 个版本,首次发布于 2022/02/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.6latest2022/04/124 年前
1.4.52022/03/044 年前
1.4.42022/02/214 年前
1.4.32022/02/184 年前
1.4.22022/02/174 年前
1.4.12022/02/174 年前

关于 @freddixx/react-native-ad-manager 的常见问题

@freddixx/react-native-ad-manager 是什么?

A react-native component for Google Ad Manager banners, interstitials and native ads.

如何安装 @freddixx/react-native-ad-manager?

在项目目录运行 npm install @freddixx/react-native-ad-manager,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react-native(>=0.59.10)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@freddixx/react-native-ad-manager 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/freddixx__react-native-ad-manager 是否存在。

@freddixx/react-native-ad-manager 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@freddixx/react-native-ad-manager 可以商用吗?

@freddixx/react-native-ad-manager 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@freddixx/react-native-ad-manager 的下载量有多少?

根据 npm 官方下载统计,@freddixx/react-native-ad-manager 在 2026/10/16 – 2026/11/14 这 30 天内被下载 16,425 次,日均约 548 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@freddixx/react-native-ad-manager 还在维护吗?

最新版本 1.4.6 发布于 2022/04/12(4 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/02/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。