Zum Inhalt springen

Erste Schritte

GitHub

Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge deinem KI-Tool die Capgo Skills mit folgendem Befehl hinzu:

Terminalfenster
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Nutze anschließend 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 bevorziehst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:

Terminalfenster
bun add @capgo/capacitor-admob
npx cap sync
import { AdMob } from '@capgo/capacitor-admob';
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.start();
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configure({
appMuted: false,
appVolume: 0.5
});
import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
await AdMob.configRequest({
maxAdContentRating: MaxAdContentRating.PG,
tagForChildDirectedTreatment: true,
testDeviceIds: ['test-device-id']
});
  • Listener: Handles entfernen, wenn Screens unmounten.
  • Einmal initialisieren: Setup beim App-Bootstrap ausführen.
  • Single Source of Truth: vertraue src/definitions.ts im GitHub Repo.

Initialisiere und starte das AdMob SDK.

import { AdMob } from '@capgo/capacitor-admob';
await AdMob.start();

AdMob-Einstellungen konfigurieren.

import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configure({
appMuted: false,
appVolume: 0.5
});

Konfiguriere die Einstellungen für Ad-Requests.

import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
await AdMob.configRequest({
maxAdContentRating: MaxAdContentRating.PG,
tagForChildDirectedTreatment: true,
testDeviceIds: ['test-device-id']
});

Erstelle eine neue Ad-Instanz.

import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adCreate({
adUnitId: 'ca-app-pub-3940256099942544/1033173712'
});

Prüfe, 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 });
}

Lade eine Ad.

import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adLoad({ id: 1 });

Eine geladene Anzeige anzeigen.

import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adShow({ id: 1 });

Eine aktuell angezeigte Anzeige ausblenden.

import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adHide({ id: 1 });

Den aktuellen Status der Tracking-Autorisierung abrufen (nur iOS).

import { AdMob, TrackingAuthorizationStatus } from '@capgo/capacitor-admob';
const { status } = await AdMob.trackingAuthorizationStatus();
if (status === TrackingAuthorizationStatus.notDetermined) {
await AdMob.requestTrackingAuthorization();
}

Den Nutzer um Tracking-Autorisierung bitten (nur iOS).

import { AdMob } from '@capgo/capacitor-admob';
const { status } = await AdMob.requestTrackingAuthorization();
console.log('User tracking status:', status);

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;
};

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[];
};

Basis-Optionen für Mobile Ads.

export type MobileAdOptions = {
/** The ad unit ID from AdMob */
adUnitId: string;
};

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,
}

Enum für die maximale Werbeinhaltsbewertung zur Einschränkung von Anzeigen basierend auf der Inhaltsbewertung.

export enum MaxAdContentRating {
/** General Audiences */
G = 'G',
/** Mature Audiences */
MA = 'MA',
/** Parental Guidance */
PG = 'PG',
/** Teen */
T = 'T',
/** Unspecified rating */
UNSPECIFIED = '',
}

Diese Seite wird aus dem Plugin- src/definitions.ts. Führe den Sync erneut aus, wenn sich der öffentliche API upstream ändert.

Wenn Sie ... verwenden Erste Schritte Um Dashboard- und API-Operationen zu planen, verbinde es mit Verwendung von @capgo/capacitor-admob für die native Funktionalität bei der Nutzung von @capgo/capacitor-admob, API Übersicht für Details zur Implementierung in der Übersicht zu API, Einführung für das Implementierungsdetail in der Einleitung, API Keys für die Implementierungsdetails in den API Keys und Geräte für die Implementierungsdetails bei Devices.