Passer au contenu

Commencer

  1. Installez le plugin

    Fenêtre de terminal
    npm i @capgo/capacitor-admob
  2. Synchroniser les projets natifs

    Fenêtre de terminal
    npx cap sync
import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
import { Capacitor } from '@capacitor/core';
// Start the Mobile Ads SDK once in your application bootstrap
await AdMob.start();
// Optional: configure global request settings
await AdMob.configure({
appMuted: false,
appVolume: 1,
});
// iOS: request tracking authorization
const platform = Capacitor.getPlatform();
if (platform === 'ios') {
await AdMob.requestTrackingAuthorization();
}
await AdMob.configRequest({
maxAdContentRating: MaxAdContentRating.T,
tagForChildDirectedTreatment: false,
tagForUnderAgeOfConsent: false,
});

android/app/src/main/AndroidManifest.xml

<application>
...
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-000000000000000~0000000000"/>
</application>

## iOSconfiguration

ios/App/App/Info.plist

<dict>
...
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-000000000000000~0000000000</string>
<key>NSUserTrackingUsageDescription</key>
<string>Your data will be used to deliver personalized ads and help us keep YourAppName free to play.</string>
</dict>
import { BannerAd } from '@capgo/capacitor-admob';
const banner = new BannerAd({
adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/banner',
position: 'bottom',
});
await banner.show();

Annonces interstitielles ou avec récompense

Section titled “Annonces interstitielles ou avec récompense”
import { InterstitialAd, RewardedAd } from '@capgo/capacitor-admob';
const interstitial = new InterstitialAd({
adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/interstitial',
});
await interstitial.load();
await interstitial.show();
const rewarded = new RewardedAd({
adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/rewarded',
});
await rewarded.load();
await rewarded.show();

## Écoutez les événements publicitaires

import { AdMob } from '@capgo/capacitor-admob';
const handle = await AdMob.addListener('adImpression', (event) => {
console.log('Ad impression', event);
});
// Later when cleaning up
await handle.remove();

## Remarques sur la plateforme

  • iOS : ajoutez l’ID de votre application AdMob à Info.plist sous la clé GADApplicationIdentifier et incluez tous les ID SKAdNetwork sur lesquels vous comptez.
  • Android : déclarez l’ID de votre application AdMob dans AndroidManifest.xml en ajoutant com.google.android.gms.ads.APPLICATION_ID à l’intérieur de la balise <application>.
  • Consentement et confidentialité : utilisez requestTrackingAuthorization() sur iOS 14+ et configRequest() indicateurs destinés aux enfants pour rester en conformité avec les règles régionales de confidentialité.
  • iOS : Sur npx cap sync, cette erreur a été résolue par The 'Pods-App' target has transitive dependencies that include statically linked binaries: (Google-Mobile-Ads-SDK and GoogleUserMessagingPlatform) en modifiant ios/App/Podfile à la ligne 4 en ajoutant use_frameworks! :linkage => :static