Zum Inhalt springen

Getting Started

GitHub

Sie können unsere AI-gestützte Einrichtung verwenden, um das Plugin zu installieren. Fügen Sie die Capgo-Fähigkeiten zu Ihrem AI-Tool hinzu, indem Sie den folgenden Befehl ausführen:

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

Verwenden Sie dann den folgenden Prompt:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-admob` plugin in my project.

Wenn Sie eine manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und die darunter angegebenen Plattform-spezifischen Anweisungen befolgen.

Terminal-Fenster
bun add @capgo/capacitor-admob
bunx cap sync
import { AdMob } from '@capgo/capacitor-admob';

Initialisieren und starten Sie die AdMob SDK.

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

Konfigurieren Sie die AdMob-Einstellungen.

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

Konfigurieren Sie die Einstellungen für die Werbeanforderung.

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

Eine neue Anzeigeninstanz erstellen.

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

Überprüfen, ob eine Anzeige geladen und bereit zum Anzeigen ist.

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

Eine Anzeige laden.

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

Ein aktuell angezeigtes Anzeigenelement verstecken.

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

Aktuelle tracking-Zustimmungsstatus abrufen (nur iOS).

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

Tracking-Zustimmung vom Benutzer anfordern (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 Werbeanforderungen.

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

Grundlegende Optionen für mobile Anzeigen.

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

Zustand der Werbeanzeigenerlaubnis 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,
}

Höchster Werbeeinblendungsgrad-Enum zur Einschränkung von Anzeigen aufgrund des Inhaltsratings.

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 generiert. src/definitions.tsRe-run die Synchronisierung, wenn die öffentliche API upstream geändert wird.

Wenn Sie das verwenden Getting Started um das Dashboard und die API-Operationen zu planen, verbinden Sie es mit Mit @capgo/capacitor-admob für die native Fähigkeit in Mit @capgo/capacitor-admob, API Übersicht zur Implementierungsdetail in API Übersicht, Einführung zur Implementierungsdetail in Einführung, API Schlüssel zur Implementierungsdetail in API Schlüssel, und Geräte für die Implementierungsdetails in Geräten.