コンテンツへスキップ

はじめに

  1. プラグインをインストール

    Terminal window
    npm i @capgo/capacitor-admob
  2. ネイティブプロジェクトを同期

    Terminal window
    npx cap sync
import { AdMob, MaxAdContentRating } from '@capgo/capacitor-admob';
// アプリケーションブートストラップで一度Mobile Ads SDKを開始
await AdMob.start();
// オプション: グローバルリクエスト設定を構成
await AdMob.configure({
appMuted: false,
appVolume: 1,
});
await AdMob.configRequest({
maxAdContentRating: MaxAdContentRating.T,
tagForChildDirectedTreatment: false,
tagForUnderAgeOfConsent: false,
});
import { BannerAd } from '@capgo/capacitor-admob';
const banner = new BannerAd({
adUnitId: 'ca-app-pub-xxxxxxxxxxxxxxxx/banner',
position: 'bottom',
});
await banner.show();

インタースティシャルまたはリワード広告

Section titled “インタースティシャルまたはリワード広告”
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();
import { AdMob } from '@capgo/capacitor-admob';
const handle = await AdMob.addListener('adImpression', (event) => {
console.log('広告インプレッション', event);
});
// 後でクリーンアップ時
await handle.remove();

プラットフォームに関する注意

Section titled “プラットフォームに関する注意”
  • iOS: Info.plistGADApplicationIdentifierキー下にAdMobアプリIDを追加し、依存するSKAdNetwork IDを含めてください。
  • Android: AndroidManifest.xml<application>タグ内にcom.google.android.gms.ads.APPLICATION_IDを追加してAdMobアプリIDを宣言します。
  • 同意とプライバシー: iOS 14+でrequestTrackingAuthorization()を使用し、configRequest()の児童向けフラグを使用して、地域のプライバシールールに準拠してください。