Getting Started
Konten ini belum tersedia dalam bahasa Anda.
-
Install the plugin
Terminal window npm i @capgo/capacitor-admobTerminal window pnpm add @capgo/capacitor-admobTerminal window yarn add @capgo/capacitor-admobTerminal window bun add @capgo/capacitor-admob -
Sync native projects
Terminal window npx cap syncTerminal window pnpm cap syncTerminal window yarn cap syncTerminal window bunx cap sync
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
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
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
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
- 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.