Getting Started
Este contenido aún no está disponible en tu idioma.
-
Install the plugin
Ventana de terminal npm i @capgo/capacitor-admobVentana de terminal pnpm add @capgo/capacitor-admobVentana de terminal yarn add @capgo/capacitor-admobVentana de terminal bun add @capgo/capacitor-admob -
Sync native projects
Ventana de terminal npx cap syncVentana de terminal pnpm cap syncVentana de terminal yarn cap syncVentana de terminal bunx cap sync
Initialize the SDK
Section titled “Initialize the SDK”import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
// Start the Mobile Ads SDK once in your application bootstrapawait AdMob.start();
// Optional: configure global request settingsawait AdMob.configure({ appMuted: false, appVolume: 1,});
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.T, tagForChildDirectedTreatment: false, tagForUnderAgeOfConsent: false,});Show a banner ad
Section titled “Show a banner ad”import { BannerAd } from '@capgo/capacitor-admob';
const banner = new BannerAd({ adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/banner', position: 'bottom',});
await banner.show();Interstitial or rewarded ads
Section titled “Interstitial or rewarded ads”import { InterstitialAd, RewardedAd } from '@capgo/capacitor-admob';
const interstitial = new InterstitialAd({ adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/interstitial',});await interstitial.load();await interstitial.show();
const rewarded = new RewardedAd({ adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/rewarded',});await rewarded.load();await rewarded.show();Listen for ad events
Section titled “Listen for ad events”import { AdMob } from '@capgo/capacitor-admob';
const handle = await AdMob.addListener('adImpression', (event) => { console.log('Ad impression', event);});
// Later when cleaning upawait handle.remove();Platform notes
Section titled “Platform notes”- iOS: Add your AdMob app ID to
Info.plistunder theGADApplicationIdentifierkey and include any SKAdNetwork IDs you rely on. - Android: Declare your AdMob app ID in
AndroidManifest.xmlby addingcom.google.android.gms.ads.APPLICATION_IDinside the<application>tag. - Consent & Privacy: Use
requestTrackingAuthorization()on iOS 14+ andconfigRequest()child-directed flags to stay compliant with regional privacy rules.