Memulai
-
Instal 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 -
Sinkronkan proyek native
Terminal window npx cap syncTerminal window pnpm cap syncTerminal window yarn cap syncTerminal window bunx cap sync
Inisialisasi SDK
Section titled “Inisialisasi SDK”import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
// Mulai Mobile Ads SDK sekali dalam bootstrap aplikasi Andaawait AdMob.start();
// Opsional: konfigurasi pengaturan request globalawait AdMob.configure({ appMuted: false, appVolume: 1,});
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.T, tagForChildDirectedTreatment: false, tagForUnderAgeOfConsent: false,});Tampilkan iklan banner
Section titled “Tampilkan iklan banner”import { BannerAd } from '@capgo/capacitor-admob';
const banner = new BannerAd({ adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/banner', position: 'bottom',});
await banner.show();Iklan interstitial atau rewarded
Section titled “Iklan interstitial atau rewarded”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();Dengarkan event iklan
Section titled “Dengarkan event iklan”import { AdMob } from '@capgo/capacitor-admob';
const handle = await AdMob.addListener('adImpression', (event) => { console.log('Ad impression', event);});
// Nanti saat pembersihanawait handle.remove();Catatan platform
Section titled “Catatan platform”- iOS: Tambahkan ID aplikasi AdMob Anda ke
Info.plistdi bawah kunciGADApplicationIdentifierdan sertakan ID SKAdNetwork yang Anda andalkan. - Android: Deklarasikan ID aplikasi AdMob Anda dalam
AndroidManifest.xmldengan menambahkancom.google.android.gms.ads.APPLICATION_IDdi dalam tag<application>. - Persetujuan & Privasi: Gunakan
requestTrackingAuthorization()di iOS 14+ dan flag child-directedconfigRequest()untuk mematuhi aturan privasi regional.