Premiers pas
Copiez un prompt de configuration avec les étapes d'installation et le guide markdown complet pour ce 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.
Installer
Section intitulée « Installation »Vous pouvez utiliser notre configuration assistée par IA pour installer le plugin. Ajoutez les skills Capgo à votre outil d'IA avec la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsUtilisez ensuite le prompt suivant :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-admob` plugin in my project.Si vous préférez la configuration manuelle, installez le plugin avec les commandes suivantes, puis suivez les instructions spécifiques à chaque plateforme ci-dessous :
bun add @capgo/capacitor-admobnpx cap syncImporter
Section intitulée « Import »import { AdMob } from '@capgo/capacitor-admob';Démarrage rapide
Section intitulée « Démarrage rapide »import { AdMob } from '@capgo/capacitor-admob';
await AdMob.start();Exemple : configuration
Section intitulée « Exemple : configuration »import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configure({ appMuted: false, appVolume: 0.5});Exemple : configRequest
Section intitulée « Exemple : configRequest »import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.PG, tagForChildDirectedTreatment: true, testDeviceIds: ['test-device-id']});Erreurs courantes
Section intitulée « Pièges courants »- Écouteurs : supprimez les handles lors du démontage des écrans.
- Initialiser une seule fois: exécutez le setup lors du bootstrap de l'app.
- Source de vérité: confiance
src/definitions.tsdans le repo GitHub.
Aperçu de API
Section intitulée « Vue d'ensemble de API »Initialisez et démarrez le SDK AdMob.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.start();configure
Section intitulée « configurer »Configurez les paramètres AdMob.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.configure({ appMuted: false, appVolume: 0.5});configRequest
Section intitulée « configRequest »Configurez les paramètres de la requête publicitaire.
import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
await AdMob.configRequest({ maxAdContentRating: MaxAdContentRating.PG, tagForChildDirectedTreatment: true, testDeviceIds: ['test-device-id']});adCreate
Section intitulée « adCreate »Créez une nouvelle instance d'annonce.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adCreate({ adUnitId: 'ca-app-pub-3940256099942544/1033173712'});adIsLoaded
Section intitulée « adIsLoaded »Vérifiez si une annonce est chargée et prête à être affichée.
import { AdMob } from '@capgo/capacitor-admob';
const isLoaded = await AdMob.adIsLoaded({ id: 1 });if (isLoaded) { await AdMob.adShow({ id: 1 });}Load an ad.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adLoad({ id: 1 });Afficher une publicité chargée.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adShow({ id: 1 });Masquer une publicité actuellement affichée.
import { AdMob } from '@capgo/capacitor-admob';
await AdMob.adHide({ id: 1 });trackingAuthorizationStatus
Section intitulée « trackingAuthorizationStatus »Récupérer le statut actuel de l'autorisation de suivi (iOS uniquement).
import { AdMob, TrackingAuthorizationStatus } from '@capgo/capacitor-admob';
const { status } = await AdMob.trackingAuthorizationStatus();if (status === TrackingAuthorizationStatus.notDetermined) { await AdMob.requestTrackingAuthorization();}requestTrackingAuthorization
Section intitulée « requestTrackingAuthorization »Demander l'autorisation de suivi à l'utilisateur (iOS uniquement).
import { AdMob } from '@capgo/capacitor-admob';
const { status } = await AdMob.requestTrackingAuthorization();console.log('User tracking status:', status);Référence de type
Section intitulée « Référence de type »AdMobConfig
Section intitulée « AdMobConfig »Options de configuration pour AdMob.
export type AdMobConfig = { /** Whether the app should be muted */ appMuted?: boolean; /** The app volume (0.0 to 1.0) */ appVolume?: number;};RequestConfig
Section intitulée « RequestConfig »Configuration pour les requêtes publicitaires.
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
Section intitulée « MobileAdOptions »Options de base pour les publicités mobiles.
export type MobileAdOptions = { /** The ad unit ID from AdMob */ adUnitId: string;};TrackingAuthorizationStatus
Section intitulée « TrackingAuthorizationStatus »Suivi du statut d'autorisation pour l'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
Section intitulée « MaxAdContentRating »Énumération du classement maximal du contenu publicitaire pour restreindre les publicités selon le contenu.
export enum MaxAdContentRating { /** General Audiences */ G = 'G', /** Mature Audiences */ MA = 'MA', /** Parental Guidance */ PG = 'PG', /** Teen */ T = 'T', /** Unspecified rating */ UNSPECIFIED = '',}Source de vérité
Section intitulée « Source de vérité »Cette page est générée à partir du src/definitions.ts. Relancez la synchronisation lorsque l’API public change en amont.
Continuer depuis Getting Started
Section intitulée « Aller plus loin après Getting Started »Si vous utilisez Premiers pas pour planifier les opérations du dashboard et de API, connectez-l’à Utiliser @capgo/capacitor-admob pour la capacité native dans Utiliser @capgo/capacitor-admob, Aperçu de API pour les détails d'implémentation dans l'aperçu de API, Introduction pour les détails d'implémentation dans l'Introduction, Clés API pour les détails d'implémentation dans les clés API, et Appareils pour le détail d’implémentation dans Devices.