@capgo/capacitor-admob

中文文档
8.2.7发布于 2026/11/09MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 2469

Capacitor plugin to bridge AdMob SDKs for iOS and Android

原始使用文档
文档目录31 节
  1. ➡️ Get started for free
  2. Key features
  3. Documentation
  4. Compatibility
  5. Install
  6. Consent (UMP)
  7. API
  8. start()
  9. configure(...)
  10. configRequest(...)
  11. requestConsentInfo(...)
  12. showConsentForm()
  13. showPrivacyOptionsForm()
  14. adCreate(...)
  15. adIsLoaded(...)
  16. adLoad(...)
  17. adShow(...)
  18. adHide(...)
  19. feedAdCreate(...)
  20. feedAdDestroy(...)
  21. feedAdLoad(...)
  22. feedAdIsLoaded(...)
  23. feedAdUpdateBounds(...)
  24. feedAdSetAutoRefresh(...)
  25. trackingAuthorizationStatus()
  26. requestTrackingAuthorization()
  27. addListener(E, ...)
  28. getPluginVersion()
  29. Interfaces
  30. Type Aliases
  31. Enums

@capgo/capacitor-admob

Show Google AdMob ads in your Capacitor app on iOS and Android: banner, interstitial, rewarded and rewarded interstitial formats from one TypeScript API. Monetize your app with the official Google Mobile Ads SDKs underneath.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-admob in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-admob to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-admob for Capacitor apps

Key features

  • Four ad formats: BannerAd, InterstitialAd, RewardedAd and RewardedInterstitialAd classes with load and show, plus hide() on BannerAd.
  • Ad lifecycle: adCreate(), adLoad(), adIsLoaded(), adShow() and adHide() give you full control over each ad instance.
  • SDK setup: start() initializes AdMob, configure() sets app-wide options and configRequest() sets request options.
  • App Tracking Transparency: trackingAuthorizationStatus() and requestTrackingAuthorization() handle the iOS tracking prompt.
  • Current SDKs: Google Mobile Ads Next Gen SDK on Android and Google Mobile Ads SDK on iOS.
  • Platforms: iOS and Android. The web implementation is a no-op stub.

AdMob SDK bridge for Capacitor apps

Android now uses the Google Mobile Ads Next Gen SDK, and iOS is aligned to Google Mobile Ads SDK 13.1.x, while preserving the existing Capacitor-facing API.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/admob/

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌
v5.*.*v5.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-admob` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-admob
npx cap sync

For apps serving users in the EEA/UK, request consent with Google's User Messaging Platform (UMP) before loading ads. Configure GDPR messages in your AdMob account first.

import { AdMob, AdmobConsentStatus } from '@capgo/capacitor-admob';

await AdMob.start();

let consentInfo = await AdMob.requestConsentInfo();
if (consentInfo.isConsentFormAvailable && consentInfo.status === AdmobConsentStatus.REQUIRED) {
  consentInfo = await AdMob.showConsentForm();
}

if (consentInfo.canRequestAds) {
  // Load ads only after consent allows ad requests.
}

To let users manage privacy choices later, call showPrivacyOptionsForm() from a settings screen when privacyOptionsRequirementStatus is REQUIRED.

For local testing on a real device, pass debugGeography and testDeviceIdentifiers to requestConsentInfo().

API

AdMob Plus Plugin interface for displaying Google AdMob ads in Capacitor apps.

start()

start() => Promise<void>

Initialize and start the AdMob SDK.

Since: 1.0.0


configure(...)

configure(config: AdMobConfig) => Promise<void>

Configure AdMob settings.

ParamTypeDescription
configAdMobConfig- Configuration options for AdMob

Since: 1.0.0


configRequest(...)

configRequest(requestConfig: RequestConfig) => Promise<void>

Configure ad request settings.

ParamTypeDescription
requestConfigRequestConfig- Request configuration options

Since: 1.0.0


requestConsentInfo(...)

requestConsentInfo(options?: AdmobConsentRequestOptions | undefined) => Promise<AdmobConsentInfo>

Request user consent information from Google's User Messaging Platform (UMP).

Call this after start() and before loading ads for users in the EEA/UK.

ParamTypeDescription
optionsAdmobConsentRequestOptions- Optional consent request options for debugging and tagging

Returns: Promise<AdmobConsentInfo>

Since: 8.2.0


showConsentForm()

showConsentForm() => Promise<AdmobConsentInfo>

Shows the Google user consent form rendered from your GDPR message configuration.

Returns: Promise<AdmobConsentInfo>

Since: 8.2.0


showPrivacyOptionsForm()

showPrivacyOptionsForm() => Promise<void>

Shows the Google privacy options form rendered from your GDPR message configuration.

Use this when your privacy message requires an in-app entry point for users to manage choices.

Since: 8.2.0


adCreate(...)

adCreate<O extends MobileAdOptions>(opts: O) => Promise<void>

Create a new ad instance.

ParamTypeDescription
optsO- Options for creating the ad, including ad unit ID

Since: 1.0.0


adIsLoaded(...)

adIsLoaded(opts: { id: number; }) => Promise<boolean>

Check if an ad is loaded and ready to be shown.

ParamTypeDescription
opts{ id: number; }- Object containing the ad ID

Returns: Promise<boolean>

Since: 1.0.0


adLoad(...)

adLoad(opts: { id: number; }) => Promise<void>

Load an ad.

ParamTypeDescription
opts{ id: number; }- Object containing the ad ID

Since: 1.0.0


adShow(...)

adShow(opts: { id: number; }) => Promise<void>

Show a loaded ad.

ParamTypeDescription
opts{ id: number; }- Object containing the ad ID

Since: 1.0.0


adHide(...)

adHide(opts: { id: number; }) => Promise<void>

Hide a currently displayed ad.

ParamTypeDescription
opts{ id: number; }- Object containing the ad ID

Since: 1.0.0


feedAdCreate(...)

feedAdCreate(opts: FeedAdCreateOptions) => Promise<{ id: number; }>

Create an in-feed ad slot (native overlay or inline banner overlay).

ParamTypeDescription
optsFeedAdCreateOptions- Feed ad configuration

Returns: Promise<{ id: number; }>

Since: 8.3.0


feedAdDestroy(...)

feedAdDestroy(opts: { id: number; }) => Promise<void>

Destroy a feed ad instance and remove its native overlay.

ParamTypeDescription
opts{ id: number; }- Object containing the feed ad id

Since: 8.3.0


feedAdLoad(...)

feedAdLoad(opts: { id: number; }) => Promise<void>

Load or reload the feed ad. Listen for feed.load / feed.loadfail events.

ParamTypeDescription
opts{ id: number; }- Object containing the feed ad id

Since: 8.3.0


feedAdIsLoaded(...)

feedAdIsLoaded(opts: { id: number; }) => Promise<boolean>

Whether the feed ad has finished loading.

ParamTypeDescription
opts{ id: number; }- Object containing the feed ad id

Returns: Promise<boolean>

Since: 8.3.0


feedAdUpdateBounds(...)

feedAdUpdateBounds(opts: FeedAdBounds & { id: number; }) => Promise<void>

Position the native overlay over an HTML placeholder. Call on scroll, resize, and orientation changes.

ParamTypeDescription
optsFeedAdBounds & { id: number; }- Feed ad id and bounds from element.getBoundingClientRect()

Since: 8.3.0


feedAdSetAutoRefresh(...)

feedAdSetAutoRefresh(opts: { id: number; autoRefreshMs: number | null; }) => Promise<void>

Enable or disable auto-refresh (minimum 30 seconds).

ParamTypeDescription
opts{ id: number; autoRefreshMs: number | null; }- Feed ad id and interval in ms, or null to disable

Since: 8.3.0


trackingAuthorizationStatus()

trackingAuthorizationStatus() => Promise<{ status: TrackingAuthorizationStatus | false; }>

Get the current tracking authorization status (iOS only).

Returns: Promise<{ status: false | TrackingAuthorizationStatus; }>

Since: 1.0.0


requestTrackingAuthorization()

requestTrackingAuthorization() => Promise<{ status: TrackingAuthorizationStatus | false; }>

Request tracking authorization from the user (iOS only).

Returns: Promise<{ status: false | TrackingAuthorizationStatus; }>

Since: 1.0.0


addListener(E, ...)

addListener<E extends AdMobPlusEventName>(eventName: E, listenerFunc: (event: AdMobPlusEventPayloadMap[E]) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Add a listener for ad events.

ParamTypeDescription
eventNameE- The name of the event to listen for
listenerFunc(event: AdMobPlusEventPayloadMap[E]) => void- The function to call when the event occurs

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 1.0.0


getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Get the native Capacitor plugin version.

Returns: Promise<{ version: string; }>

Since: 1.0.0


Interfaces

PluginListenerHandle

PropType
remove() => Promise<void>

Type Aliases

AdMobConfig

Configuration options for AdMob.

{ /** Whether the app should be muted / appMuted?: boolean; /* The app volume (0.0 to 1.0) */ appVolume?: number; }

RequestConfig

Configuration for ad requests.

{ /** Maximum ad content rating / maxAdContentRating?: MaxAdContentRating; /* Whether to use the same app key / sameAppKey?: boolean; /* Tag for child-directed treatment (true, false, or null for unspecified) / tagForChildDirectedTreatment?: boolean | null; /* Tag for under age of consent (true, false, or null for unspecified) / tagForUnderAgeOfConsent?: boolean | null; /* Array of test device IDs */ testDeviceIds?: string[]; }

AdmobConsentInfo

Consent information returned by UMP.

{ /** The consent status of the user. / status: AdmobConsentStatus; /* If true, a consent form is available. / isConsentFormAvailable?: boolean; /* If true, an ad request can be made. / canRequestAds: boolean; /* Privacy options requirement status of the user. */ privacyOptionsRequirementStatus: PrivacyOptionsRequirementStatus; }

AdmobConsentRequestOptions

Options for requesting UMP consent information.

{ /** Sets the debug geography to test consent locally. / debugGeography?: AdmobConsentDebugGeography; /* * Test device IDs to allow for consent debugging. * On iOS, the ID may change if you uninstall and reinstall the app. / testDeviceIdentifiers?: string[]; /* * When true, tags the user as under the age of consent for UMP requests. * * @default false */ tagForUnderAgeOfConsent?: boolean; }

MobileAdOptions

Base options for mobile ads.

{ /** The ad unit ID from AdMob */ adUnitId: string; }

FeedAdCreateOptions

Options for creating an in-feed ad instance.

Policy: AdMob counts native impressions and clicks only when assets render inside {@link https://developers.google.com/admob/android/native/advanced | NativeAdView} / GADNativeAdView with the AdChoices icon and an ad attribution badge. This plugin overlays a compliant native view on your placeholder. Optional {@link FeedNativeAdAssets} are returned on feed.load for layout sizing only, not for manual click forwarding.

{ /** Native advanced or inline banner. / format: FeedAdFormat; /* AdMob ad unit ID. / adUnitId: string; /* Optional key echoed on feed events for your feed slot. / positionKey?: string; /* * Auto-refresh interval in milliseconds. AdMob requires at least 30 seconds. * Omit or pass null to disable auto-refresh. / autoRefreshMs?: number | null; /* Template colors when format is native. */ nativeStyle?: FeedNativeAdStyle; }

FeedAdFormat

In-feed ad format. Both use a native overlay aligned to an HTML placeholder.

'native' | 'banner'

FeedNativeAdStyle

Optional colors for the built-in native ad template (hex strings, e.g. #ffffff).

{ backgroundColor?: string; headlineTextColor?: string; bodyTextColor?: string; ctaBackgroundColor?: string; ctaTextColor?: string; }

FeedAdBounds

Bounds of the HTML placeholder, in CSS pixels relative to the WebView viewport.

{ x: number; y: number; width: number; height: number; /** When false, the native overlay is hidden (e.g. off-screen while scrolling). / visible: boolean; /* window.devicePixelRatio from the WebView. Defaults to 1 on web. */ density?: number; }

AdMobPlusEventName

(typeof AdMobPlusEvents)[keyof typeof AdMobPlusEvents]

AdMobPlusEventPayloadMap

Maps each {@link AdMobPlusEventName} to the payload shape emitted from native code.

{ [AdMobPlusEvents.AdClick]: AdMobPlusAdIdPayload; [AdMobPlusEvents.AdDismiss]: AdMobPlusAdIdPayload; [AdMobPlusEvents.AdImpression]: AdMobPlusAdIdPayload; [AdMobPlusEvents.AdLoad]: AdMobPlusAdIdPayload; [AdMobPlusEvents.AdLoadFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.AdReward]: AdMobPlusAdRewardPayload; [AdMobPlusEvents.AdShow]: AdMobPlusAdIdPayload; [AdMobPlusEvents.AdShowFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.BannerClick]: AdMobPlusAdIdPayload; [AdMobPlusEvents.BannerClose]: AdMobPlusAdIdPayload; [AdMobPlusEvents.BannerImpression]: AdMobPlusAdIdPayload; [AdMobPlusEvents.BannerLoad]: AdMobPlusAdIdPayload; [AdMobPlusEvents.BannerLoadFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.BannerOpen]: AdMobPlusAdIdPayload; [AdMobPlusEvents.BannerSizeChange]: AdMobPlusAdIdPayload; [AdMobPlusEvents.InterstitialDismiss]: AdMobPlusAdIdPayload; [AdMobPlusEvents.InterstitialImpression]: AdMobPlusAdIdPayload; [AdMobPlusEvents.InterstitialLoad]: AdMobPlusAdIdPayload; [AdMobPlusEvents.InterstitialLoadFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.InterstitialShow]: AdMobPlusAdIdPayload; [AdMobPlusEvents.InterstitialShowFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.RewardedDismiss]: AdMobPlusAdIdPayload; [AdMobPlusEvents.RewardedImpression]: AdMobPlusAdIdPayload; [AdMobPlusEvents.RewardedInterstitialDismiss]: AdMobPlusAdIdPayload; [AdMobPlusEvents.RewardedInterstitialImpression]: AdMobPlusAdIdPayload; [AdMobPlusEvents.RewardedInterstitialLoad]: AdMobPlusAdIdPayload; [AdMobPlusEvents.RewardedInterstitialLoadFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.RewardedInterstitialReward]: AdMobPlusAdRewardPayload; [AdMobPlusEvents.RewardedInterstitialShow]: AdMobPlusAdIdPayload; [AdMobPlusEvents.RewardedInterstitialShowFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.RewardedLoad]: AdMobPlusAdIdPayload; [AdMobPlusEvents.RewardedLoadFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.RewardedReward]: AdMobPlusAdRewardPayload; [AdMobPlusEvents.RewardedShow]: AdMobPlusAdIdPayload; [AdMobPlusEvents.RewardedShowFail]: AdMobPlusAdFailurePayload; [AdMobPlusEvents.FeedClick]: AdMobPlusFeedAdIdPayload; [AdMobPlusEvents.FeedClose]: AdMobPlusFeedAdIdPayload; [AdMobPlusEvents.FeedImpression]: AdMobPlusFeedAdIdPayload; [AdMobPlusEvents.FeedLoad]: AdMobPlusFeedLoadPayload; [AdMobPlusEvents.FeedLoadFail]: AdMobPlusAdFailurePayload & AdMobPlusFeedAdIdPayload; [AdMobPlusEvents.FeedOpen]: AdMobPlusFeedAdIdPayload; [AdMobPlusEvents.FeedRefresh]: AdMobPlusFeedAdIdPayload; }

AdMobPlusAdIdPayload

Event payload always includes the native ad instance id (adId). iOS also emits legacy id.

{ adId: number; id?: number; }

AdMobPlusAdFailurePayload

Load and fullscreen show failure payloads from native LoadAdError / FullScreenContentError.

AdMobPlusAdIdPayload & { code: number; message: string; /** Legacy iOS failure field; same string as message when present. */ error?: string; }

AdMobPlusAdRewardPayload

Reward callbacks include the earned reward plus adId.

AdMobPlusAdIdPayload & { reward: { amount: number; type: string; }; }

AdMobPlusFeedAdIdPayload

In-feed ad events use feedAdId (same numeric id as feedAdCreate).

{ feedAdId: number; positionKey?: string; format?: 'native' | 'banner'; }

AdMobPlusFeedLoadPayload

AdMobPlusFeedAdIdPayload & { assets?: Record<string, unknown>; }

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }

Enums

MaxAdContentRating

MembersValueDescription
G'G'General Audiences
MA'MA'Mature Audiences
PG'PG'Parental Guidance
T'T'Teen
UNSPECIFIED''Unspecified rating

AdmobConsentStatus

MembersValueDescription
NOT_REQUIRED'NOT_REQUIRED'User consent not required.
OBTAINED'OBTAINED'User consent already obtained.
REQUIRED'REQUIRED'User consent required but not yet obtained.
UNKNOWN'UNKNOWN'Unknown consent status. Call requestConsentInfo() to update it.

PrivacyOptionsRequirementStatus

MembersValueDescription
NOT_REQUIRED'NOT_REQUIRED'Privacy options entry point is not required.
REQUIRED'REQUIRED'Privacy options entry point is required.
UNKNOWN'UNKNOWN'Privacy options requirement status is unknown.

AdmobConsentDebugGeography

MembersValueDescription
DISABLED0Debug geography disabled.
EEA1Geography appears as in EEA for debug devices.
NOT_EEA2Geography appears as not in EEA for debug devices.
US3Geography appears as in a regulated US state for debug devices.
OTHER4Geography appears as OTHER for debug devices.

TrackingAuthorizationStatus

MembersValueDescription
notDetermined0User has not yet received an authorization request
restricted1User restricted, device is unable to provide authorization
denied2User denied authorization
authorized3User authorized access

版本与发布记录

@capgo/capacitor-admob 共发布 55 个版本,首次发布于 2025/10/10;过去 12 个月发布了 48 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.2.7latest2026/11/09今天
8.2.62026/11/027 天前
8.2.52026/10/1822 天前
8.2.42026/10/1525 天前
8.2.32026/10/1327 天前
8.2.22026/10/1228 天前

关于 @capgo/capacitor-admob 的常见问题

@capgo/capacitor-admob 是什么?

Capacitor plugin to bridge AdMob SDKs for iOS and Android

如何安装 @capgo/capacitor-admob?

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

@capgo/capacitor-admob 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-admob 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-admob 可以商用吗?

@capgo/capacitor-admob 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-admob 的下载量有多少?

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

@capgo/capacitor-admob 还在维护吗?

最新版本 8.2.7 发布于 2026/11/09(今天);至今共发布 55 个版本,其中过去 12 个月发布了 48 个;首次发布于 2025/10/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。