本文へ移動

インタースティシャル広告

インタースティシャルはホストアプリの画面を覆うフルスクリーン広告です。画面遷移やゲームのレベル間など、自然な区切りで表示します。ユーザーは広告先へ進むか、閉じてアプリに戻れます。形式の説明は Google のインタースティシャル広告ガイド(Android / iOS)を見てください。

アプリ内報酬を渡さない場合に使います。初期化同意 のあとで呼び出します。事前に準備し、先にリスナーを登録し、準備ができてから表示します。

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(...)

Loads an interstitial ad and returns the loaded ad unit ID.

prepareInterstitial(options: AdOptions) => Promise<AdLoadInfo>

method showInterstitial(...)

Shows a loaded interstitial ad.

showInterstitial(options?: AdShowOptions | undefined) => Promise<void>

interface AdOptions

Common options for requesting an ad.

Prop Type Description Default Since
adId string The ad unit ID to load. 1.1.2
isTesting boolean Whether to request a test ad. false 1.1.2
margin number The banner margin in logical display units (dp on Android and points on iOS). For BOTTOM_CENTER, this is the bottom margin. For TOP_CENTER, this is the top margin. 0 1.1.2
npa boolean Whether to request non-personalized ads. false 1.2.0
immersiveMode boolean Whether to display a full-screen ad in immersive mode on Android. 7.0.3

showInterstitial()adId を渡さないと、最後に準備した広告を表示します。

複数の広告を準備する

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' });

isTestingテスト を参照してください。

ロード、表示、閉じる操作、失敗のイベントは 広告イベント にあります。