Langsung ke konten

Memulai

  1. Instal plugin

    Terminal window
    npm i @capgo/capacitor-admob
  2. Sinkronkan proyek native

    Terminal window
    npx cap sync
import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
// Mulai Mobile Ads SDK sekali dalam bootstrap aplikasi Anda
await AdMob.start();
// Opsional: konfigurasi pengaturan request global
await AdMob.configure({
appMuted: false,
appVolume: 1,
});
await AdMob.configRequest({
maxAdContentRating: MaxAdContentRating.T,
tagForChildDirectedTreatment: false,
tagForUnderAgeOfConsent: false,
});
import { BannerAd } from '@capgo/capacitor-admob';
const banner = new BannerAd({
adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/banner',
position: 'bottom',
});
await banner.show();
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();
import { AdMob } from '@capgo/capacitor-admob';
const handle = await AdMob.addListener('adImpression', (event) => {
console.log('Ad impression', event);
});
// Nanti saat pembersihan
await handle.remove();
  • iOS: Tambahkan ID aplikasi AdMob Anda ke Info.plist di bawah kunci GADApplicationIdentifier dan sertakan ID SKAdNetwork yang Anda andalkan.
  • Android: Deklarasikan ID aplikasi AdMob Anda dalam AndroidManifest.xml dengan menambahkan com.google.android.gms.ads.APPLICATION_ID di dalam tag <application>.
  • Persetujuan & Privasi: Gunakan requestTrackingAuthorization() di iOS 14+ dan flag child-directed configRequest() untuk mematuhi aturan privasi regional.