Getting Started
-
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
Section titled “Initialize the SDK”import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';import { Capacitor } from '@capacitor/core';
// Start the Mobile Ads SDK once in your application bootstrapawait AdMob.start();
// Optional: configure global request settingsawait AdMob.configure({ appMuted: false, appVolume: 1,});
// iOS: request tracking authorizationconst platform = Capacitor.getPlatform();if (platform === 'ios') { await AdMob.requestTrackingAuthorization();}
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.T, tagForChildDirectedTreatment: false, tagForUnderAgeOfConsent: false,});Android configuration
Section titled “Android configuration”android/app/src/main/AndroidManifest.xml
<application> ... <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-000000000000000~0000000000"/></application>## iOS configuration
ios/App/App/Info.plist
<dict> ... <key>GADApplicationIdentifier</key> <string>ca-app-pub-000000000000000~0000000000</string> <key>NSUserTrackingUsageDescription</key> <string>Your data will be used to deliver personalized ads and help us keep YourAppName free to play.</string></dict>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. - iOS: On
npx cap syncgot this errorThe 'Pods-App' target has transitive dependencies that include statically linked binaries: (Google-Mobile-Ads-SDK and GoogleUserMessagingPlatform)solved by editingios/App/Podfileon line 4 addinguse_frameworks! :linkage => :static