Zum Inhalt springen

Einstieg

Installieren

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

Initialisieren und den AdMob SDK starten.

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

Einstellungen für Anzeigenanforderungen konfigurieren.

import { AdMob } 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 });

Ein geladenes Anzeigen anzeigen.

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

Eine derzeit angezeigte Anzeige ausblenden.

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

Ermitteln Sie den aktuellen Zustand der Trackingberechtigung (nur iOS).

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

Bitten Sie den Benutzer um die Trackingberechtigung (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 Anforderungen an Werbung.

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 Werbung.

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

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

Maximale Anzeigeninhaltsbewertungenum, die zur Einschränkung von Anzeigen auf der Grundlage der Inhaltsbewertung verwendet wird.

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 the sync, wenn die öffentliche API upstream geändert wird.