Erste Schritte
Kopiere einen Setup-Prompt mit den Installationsschritten und dem vollständigen Markdown-Guide für dieses Plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-admob`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/admob/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installieren
Abschnitt „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge die Capgo Skills mit dem folgenden Befehl deinem KI-Tool hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze dann diesen Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-admob` plugin in my project.Wenn du ein manuelles Setup bevorzugst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:
bun add @capgo/capacitor-admobnpx cap syncImportieren
Abschnitt mit dem Titel „Import“import { AdMob } from '@capgo/capacitor-admob';Quickstart
Abschnitt „Quick start“import { AdMob } from '@capgo/capacitor-admob';
await AdMob.start();Beispiel: Konfiguration
Abschnitt mit dem Titel „Beispiel: Konfiguration“import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configure({ appMuted: false, appVolume: 0.5});Beispiel: configRequest
Abschnitt mit dem Titel „Beispiel: configRequest“import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.PG, tagForChildDirectedTreatment: true, testDeviceIds: ['test-device-id']});Häufige Stolperfallen
Abschnitt „Häufige Fallstricke“- Listener: Handles beim Unmounten von Screens entfernen.
- Einmalige Initialisierung: Setup beim App-Bootstrap ausführen.
- Single Source of Truth: Vertrauen
src/definitions.tsim GitHub Repo.
API Übersicht
Abschnitt „API Übersicht“start
Abschnitt „Start“Initialisiere und starte das AdMob SDK.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.start();configure
Abschnitt „Konfiguration“Konfiguriere die AdMob-Einstellungen.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configure({ appMuted: false, appVolume: 0.5});configRequest
Abschnitt mit dem Titel „configRequest“Ad-Request-Einstellungen konfigurieren.
import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.PG, tagForChildDirectedTreatment: true, testDeviceIds: ['test-device-id']});Neue Ad-Instanz erstellen.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adCreate({ adUnitId: 'ca-app-pub-3940256099942544/1033173712'});adIsLoaded
Abschnitt mit dem Titel „adIsLoaded“Prüfen, ob eine Ad geladen und bereit zur Anzeige ist.
import { AdMob } from '@capgo/capacitor-admob';
const isLoaded = await AdMob.adIsLoaded({ id: 1 });if (isLoaded) { await AdMob.adShow({ id: 1 });}Eine Ad laden.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adLoad({ id: 1 });adShow
Abschnitt „adShow“Zeigt eine geladene Anzeige an.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adShow({ id: 1 });adHide
Abschnitt „adHide“Blendet die aktuell angezeigte Anzeige aus.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adHide({ id: 1 });trackingAuthorizationStatus
Abschnitt „trackingAuthorizationStatus“Ruft den aktuellen Status der Tracking-Autorisierung ab (nur iOS).
import { AdMob, TrackingAuthorizationStatus } from '@capgo/capacitor-admob';
const { status } = await AdMob.trackingAuthorizationStatus();if (status === TrackingAuthorizationStatus.notDetermined) { await AdMob.requestTrackingAuthorization();}requestTrackingAuthorization
Abschnitt „requestTrackingAuthorization“Fordert die Tracking-Autorisierung beim Nutzer an (nur iOS).
import { AdMob } from '@capgo/capacitor-admob';
const { status } = await AdMob.requestTrackingAuthorization();console.log('User tracking status:', status);Typreferenz
Abschnitt mit dem Titel „Typreferenz“AdMobConfig
Abschnitt „AdMobConfig“Konfigurationsoptionen für AdMob.
export type AdMobConfig = { /** Whether the app should be muted */ appMuted?: boolean; /** The app volume (0.0 to 1.0) */ appVolume?: number;};RequestConfig
Abschnitt „RequestConfig“Konfiguration für Ad-Requests.
export type RequestConfig = { /** Maximum ad content rating */ maxAdContentRating?: MaxAdContentRating; /** Whether to use the same app key */ sameAppKey?: boolean; /** Tag for child-directed treatment (true, false, or null for unspecified) */ tagForChildDirectedTreatment?: boolean | null; /** Tag for under age of consent (true, false, or null for unspecified) */ tagForUnderAgeOfConsent?: boolean | null; /** Array of test device IDs */ testDeviceIds?: string[];};MobileAdOptions
Abschnitt „MobileAdOptions“Basis-Optionen für Mobile Ads.
export type MobileAdOptions = { /** The ad unit ID from AdMob */ adUnitId: string;};TrackingAuthorizationStatus
Abschnitt „TrackingAuthorizationStatus“Status der Tracking-Autorisierung für iOS App Tracking Transparency.
export enum TrackingAuthorizationStatus { /** User has not yet received an authorization request */ notDetermined = 0, /** User restricted, device is unable to provide authorization */ restricted = 1, /** User denied authorization */ denied = 2, /** User authorized access */ authorized = 3,}MaxAdContentRating
Abschnitt „MaxAdContentRating“Enum für die maximale Werbeinhaltsbewertung zur Einschränkung von Anzeigen basierend auf dem Content Rating.
export enum MaxAdContentRating { /** General Audiences */ G = 'G', /** Mature Audiences */ MA = 'MA', /** Parental Guidance */ PG = 'PG', /** Teen */ T = 'T', /** Unspecified rating */ UNSPECIFIED = '',}Source of Truth
Abschnitt mit dem Titel „Source of Truth“Diese Seite wird aus dem Plugin generiert src/definitions.ts. Führe den Sync erneut aus, wenn sich das öffentliche API upstream ändert.
Weiter geht's nach Getting Started
Abschnitt: „Weiter geht’s mit Getting Started“Wenn du es nutzt Erste Schritte um Dashboard- und API-Operationen zu planen, verbinde es mit @capgo/capacitor-admob verwenden für die native Funktionalität bei der Nutzung von @capgo/capacitor-admob, API Übersicht für Details zur Implementierung im API Overview, Einführung für die Implementierungsdetails in der Einleitung, API Schlüssel für das Implementierungsdetail in API Keys und Geräte für das Implementierungsdetail in Devices.