Vai al contenuto

Guida rapida

GitHub

Puoi usare il nostro Setup assistito dall'AI per installare il plugin. Aggiungi le skill Capgo al tuo tool AI con il comando seguente:

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

Poi usa questo prompt:

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

Se preferisci il Setup manuale, installa il plugin eseguendo i comandi seguenti e segui le istruzioni specifiche per piattaforma qui sotto:

Finestra del terminale
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: rimuovi gli handle quando gli screen vengono smontati.
  • Inizializza una volta: esegui il setup durante il bootstrap dell'app.
  • Fonte di verità: fidati src/definitions.ts nel repo GitHub.

Inizializza e avvia l'SDK di AdMob.

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

Configura le impostazioni di AdMob.

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

Configura le impostazioni della richiesta pubblicitaria.

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

Crea una nuova istanza dell'annuncio.

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

Verifica se un annuncio è caricato e pronto per essere mostrato.

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

Carica un annuncio.

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

Mostra un annuncio caricato.

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

Nascondi l'annuncio attualmente visualizzato.

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

Ottieni lo stato attuale dell'autorizzazione al tracciamento (solo iOS).

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

Richiedi l'autorizzazione al tracciamento all'utente (solo iOS).

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

Opzioni di configurazione per AdMob.

export type AdMobConfig = {
/** Whether the app should be muted */
appMuted?: boolean;
/** The app volume (0.0 to 1.0) */
appVolume?: number;
};

Configurazione per le richieste degli annunci.

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

Opzioni di base per gli annunci mobile.

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

Monitora lo stato dell'autorizzazione per l'App Tracking Transparency su iOS.

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 del rating massimo dei contenuti pubblicitari per limitare gli annunci in base alla classificazione.

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

Questa pagina è generata dal src/definitions.ts. Riesegui la sync quando il API pubblico cambia upstream.

Se stai usando Guida rapida per pianificare dashboard e operazioni API, collegalo a Utilizzo di @capgo/capacitor-admob per la funzionalità nativa in Utilizzo di @capgo/capacitor-admob, API Panoramica per i dettagli di implementazione in Panoramica di API, Introduzione per i dettagli implementativi nell'Introduzione, Chiavi API per i dettagli implementativi in API Keys, e Dispositivi per i dettagli implementativi in Dispositivi.