Comenzando
-
Instalar el 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 -
Sincronizar proyectos nativos
Ventana de terminal npx cap syncVentana de terminal pnpm cap syncVentana de terminal yarn cap syncVentana de terminal bunx cap sync
Inicializar el SDK
Section titled “Inicializar el SDK”import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
// Iniciar el SDK de Mobile Ads una vez en el arranque de su aplicaciónawait AdMob.start();
// Opcional: configurar ajustes de solicitud globalawait AdMob.configure({ appMuted: false, appVolume: 1,});
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.T, tagForChildDirectedTreatment: false, tagForUnderAgeOfConsent: false,});Mostrar un anuncio de banner
Section titled “Mostrar un anuncio de banner”import { BannerAd } from '@capgo/capacitor-admob';
const banner = new BannerAd({ adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/banner', position: 'bottom',});
await banner.show();Anuncios intersticiales o de recompensa
Section titled “Anuncios intersticiales o de recompensa”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();Escuchar eventos de anuncios
Section titled “Escuchar eventos de anuncios”import { AdMob } from '@capgo/capacitor-admob';
const handle = await AdMob.addListener('adImpression', (event) => { console.log('Impresión de anuncio', event);});
// Más tarde al limpiarawait handle.remove();Notas de plataforma
Section titled “Notas de plataforma”- iOS: Agregue su ID de aplicación de AdMob a
Info.plistbajo la claveGADApplicationIdentifiere incluya cualquier ID de SKAdNetwork en el que confíe. - Android: Declare su ID de aplicación de AdMob en
AndroidManifest.xmlagregandocom.google.android.gms.ads.APPLICATION_IDdentro de la etiqueta<application>. - Consentimiento y privacidad: Usar
requestTrackingAuthorization()en iOS 14+ y banderas deconfigRequest()dirigidas a niños para cumplir con las reglas de privacidad regionales.