Annonces interstitielles
Les annonces interstitielles occupent tout l’écran et recouvrent l’application hôte. Affichez-les lors d’une transition naturelle, par exemple entre activités ou niveaux de jeu. L’utilisateur peut suivre l’annonce ou la fermer pour revenir à l’application. Les guides Google sur les interstitielles pour Android et iOS expliquent ce format.
Utilisez une interstitielle lorsque l’utilisateur ne doit pas recevoir de récompense dans l’application. Appelez cette méthode après l’initialisation et le consentement. Préparez l’annonce à l’avance, enregistrez d’abord les écouteurs et affichez-la uniquement lorsqu’elle est prête.
import { AdLoadInfo, AdMob, AdMobRevenueData, AdOptions, InterstitialAdPluginEvents } from '@capacitor-community/admob';
await AdMob.addListener(InterstitialAdPluginEvents.Loaded, (info: AdLoadInfo) => {
console.log('Interstitial loaded', info.adUnitId);
});
await AdMob.addListener(InterstitialAdPluginEvents.FailedToLoad, console.error);
await AdMob.addListener(InterstitialAdPluginEvents.AdImpression, (data: AdMobRevenueData) => {
console.log(data);
});
const options: AdOptions = {
adId: 'YOUR_AD_UNIT_ID',
// isTesting: true,
// npa: true,
// immersiveMode: true,
};
const { adUnitId } = await AdMob.prepareInterstitial(options);
await AdMob.showInterstitial({ adId: adUnitId });
method prepareInterstitial(...)
Charge une annonce interstitielle et renvoie l’identifiant du bloc d’annonces chargé.
prepareInterstitial(options: AdOptions) => Promise<AdLoadInfo>
method showInterstitial(...)
Affiche une annonce interstitielle déjà chargée.
showInterstitial(options?: AdShowOptions | undefined) => Promise<void>
interface AdOptions
Options communes de demande d’annonce.
| Propriété | Type | Description | Valeur par défaut | Depuis |
|---|---|---|---|---|
adId |
string |
Identifiant du bloc d’annonces à charger. | 1.1.2 | |
isTesting |
boolean |
Indique si une annonce de test doit être demandée. | false | 1.1.2 |
margin |
number |
Marge de la bannière en unités logiques d’affichage : dp sur Android et points sur iOS. Pour BOTTOM_CENTER, il s’agit de la marge inférieure. Pour TOP_CENTER, il s’agit de la marge supérieure. |
0 | 1.1.2 |
npa |
boolean |
Indique si des annonces non personnalisées doivent être demandées. | false | 1.2.0 |
immersiveMode |
boolean |
Indique si une annonce plein écran doit être affichée en mode immersif sur Android. | 7.0.3 |
Sans adId passé à showInterstitial(), l’annonce préparée le plus récemment est affichée.
Préparer plusieurs annonces
await AdMob.prepareInterstitial({ adId: 'ca-app-pub-xxx/interstitial-1' });
await AdMob.prepareInterstitial({ adId: 'ca-app-pub-xxx/interstitial-2' });
await AdMob.showInterstitial({ adId: 'ca-app-pub-xxx/interstitial-1' });
Consultez Tests pour isTesting.
Les événements de chargement, d’affichage, de fermeture et d’échec figurent dans Événements publicitaires.