Erste Schritte
-
Plugin installieren
Terminal-Fenster npm i @capgo/capacitor-admobTerminal-Fenster pnpm add @capgo/capacitor-admobTerminal-Fenster yarn add @capgo/capacitor-admobTerminal-Fenster bun add @capgo/capacitor-admob -
Native Projekte synchronisieren
Terminal-Fenster npx cap syncTerminal-Fenster pnpm cap syncTerminal-Fenster yarn cap syncTerminal-Fenster bunx cap sync
SDK initialisieren
Section titled “SDK initialisieren”import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
// Starten Sie das Mobile Ads SDK einmal beim Anwendungsstartawait AdMob.start();
// Optional: Globale Anforderungseinstellungen konfigurierenawait AdMob.configure({ appMuted: false, appVolume: 1,});
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.T, tagForChildDirectedTreatment: false, tagForUnderAgeOfConsent: false,});Banner-Anzeige anzeigen
Section titled “Banner-Anzeige anzeigen”import { BannerAd } from '@capgo/capacitor-admob';
const banner = new BannerAd({ adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/banner', position: 'bottom',});
await banner.show();Interstitial- oder Belohnungsanzeigen
Section titled “Interstitial- oder Belohnungsanzeigen”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();Auf Anzeigenereignisse lauschen
Section titled “Auf Anzeigenereignisse lauschen”import { AdMob } from '@capgo/capacitor-admob';
const handle = await AdMob.addListener('adImpression', (event) => { console.log('Ad impression', event);});
// Später beim Aufräumenawait handle.remove();Plattformhinweise
Section titled “Plattformhinweise”- iOS: Fügen Sie Ihre AdMob App-ID zu
Info.plistunter dem SchlüsselGADApplicationIdentifierhinzu und fügen Sie alle SKAdNetwork-IDs hinzu, auf die Sie angewiesen sind. - Android: Deklarieren Sie Ihre AdMob App-ID in
AndroidManifest.xml, indem Siecom.google.android.gms.ads.APPLICATION_IDinnerhalb des<application>-Tags hinzufügen. - Einwilligung & Datenschutz: Verwenden Sie
requestTrackingAuthorization()auf iOS 14+ und dieconfigRequest()Flags für kinderfreundliche Inhalte, um die regionalen Datenschutzbestimmungen einzuhalten.