本文へ移動

リワード広告

リワード広告は、動画・プレイアブル・アンケートへの操作と引き換えにアプリ内アイテムを渡す形式です。形式の説明は Google のリワード広告ガイド(Android / iOS)を見てください。

リワード広告は報酬フローとして扱い、報酬なしのインタースティシャルの代わりにはしません。初期化同意 のあとで呼び出します。報酬は戻り値または Rewarded イベントからのみ付与し、Dismissed では付与しません。

リワード動画

専用の報酬フローではリワード広告を使います。

import {
  AdLoadInfo,
  AdMob,
  AdMobRevenueData,
  AdMobRewardItem,
  RewardAdOptions,
  RewardAdPluginEvents,
} from '@capacitor-community/admob';

await AdMob.addListener(RewardAdPluginEvents.Loaded, (info: AdLoadInfo) => {
  console.log('Rewarded ad loaded', info.adUnitId);
});
await AdMob.addListener(RewardAdPluginEvents.FailedToLoad, console.error);
await AdMob.addListener(RewardAdPluginEvents.Rewarded, (reward: AdMobRewardItem) => {
  console.log('Reward earned', reward.amount, reward.type);
});
await AdMob.addListener(RewardAdPluginEvents.AdImpression, (data: AdMobRevenueData) => {
  console.log(data);
});

const options: RewardAdOptions = {
  adId: 'YOUR_AD_UNIT_ID',
  // isTesting: true,
  // npa: true,
  // immersiveMode: true,
  // ssv: {
  //   userId: 'USER_ID',
  //   customData: JSON.stringify({ placement: 'bonus' }),
  // },
};
await AdMob.prepareRewardVideoAd(options);
const rewardItem = await AdMob.showRewardVideoAd();
// Grant the reward once, using this result or the Rewarded event — not both.
console.log(rewardItem);

method prepareRewardVideoAd(...)

Loads a rewarded ad and returns the loaded ad unit ID.

prepareRewardVideoAd(options: RewardAdOptions) => Promise<AdLoadInfo>

method showRewardVideoAd(...)

Shows a loaded rewarded ad and resolves when the user earns the reward.

showRewardVideoAd(options?: AdShowOptions | undefined) => Promise<AdMobRewardItem>

interface RewardAdOptions

Options for loading a rewarded ad.

Prop Type Description Default Since
ssv AtLeastOne&lt;{ /** * A user identifier passed to the SSV callback. */ userId: string; /** * Custom data passed to the SSV callback. */ customData: string; }&gt; Server-side verification options for the rewarded ad. Provide at least one of userId or customData.
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

interface AdMobRewardItem

The reward earned by the user after viewing a rewarded ad.

Prop Type Description
type string The reward item type configured for the ad unit.
amount number The reward amount earned by the user.

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

複数の広告を準備する

await AdMob.prepareRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-1' });
await AdMob.prepareRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-2' });

const reward = await AdMob.showRewardVideoAd({ adId: 'ca-app-pub-xxx/reward-1' });

リワード付きインタースティシャル

リワード付きインタースティシャルは、自然な遷移で自動表示される報酬付きフルスクリーン広告です。通常のリワードと違い、視聴のオプトインは不要です。形式の説明は Google のリワード付きインタースティシャルガイド(Android / iOS)を見てください。

報酬体験がアプリの自然な遷移に乗る場合は、リワード付きインタースティシャルを使います。

import {
  AdMob,
  AdMobRewardInterstitialItem,
  RewardInterstitialAdOptions,
  RewardInterstitialAdPluginEvents,
} from '@capacitor-community/admob';

await AdMob.addListener(RewardInterstitialAdPluginEvents.FailedToLoad, console.error);

const options: RewardInterstitialAdOptions = {
  adId: 'YOUR_AD_UNIT_ID',
};
const { adUnitId } = await AdMob.prepareRewardInterstitialAd(options);
const rewardItem: AdMobRewardInterstitialItem = await AdMob.showRewardInterstitialAd({
  adId: adUnitId,
});
console.log(rewardItem);

method prepareRewardInterstitialAd(...)

Loads a rewarded interstitial ad and returns the loaded ad unit ID.

prepareRewardInterstitialAd(options: RewardInterstitialAdOptions) => Promise<AdLoadInfo>

method showRewardInterstitialAd(...)

Shows a loaded rewarded interstitial ad and resolves when the user earns the reward.

showRewardInterstitialAd(options?: AdShowOptions | undefined) => Promise<AdMobRewardInterstitialItem>

interface RewardInterstitialAdOptions

Options for loading a rewarded interstitial ad.

Prop Type Description Default Since
ssv AtLeastOne&lt;{ /** * A user identifier passed to the SSV callback. */ userId: string; /** * Custom data passed to the SSV callback. */ customData: string; }&gt; Server-side verification options for the rewarded interstitial ad. Provide at least one of userId or customData.
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

interface AdMobRewardInterstitialItem

The reward earned by the user after viewing a rewarded interstitial ad.

Prop Type Description
type string The reward item type configured for the ad unit.
amount number The reward amount earned by the user.

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

サーバーサイド検証

サーバーサイド検証(SSV)は、報酬が得られたことをバックエンドで確認するための仕組みです。Google の SSV の説明 を見てください。コールバックは本番広告でのみ送られ、テスト広告では SSV エンドポイントは呼ばれません。

ssv のペイロードをローカルで確認するには、RewardAdPluginEvents.Rewarded のあとにモックリクエストを送れます。ENVIRONMENT_IS_DEVELOPMENT は自分の開発用フラグに置き換えてください。

const userId = 'USER_ID';
const customData = JSON.stringify({ placement: 'bonus' });

await AdMob.addListener(RewardAdPluginEvents.Rewarded, async () => {
  if (!ENVIRONMENT_IS_DEVELOPMENT) {
    return;
  }
  try {
    const params = new URLSearchParams({
      ad_network: 'TEST',
      ad_unit: 'TEST',
      custom_data: customData,
      reward_amount: 'TEST',
      reward_item: 'TEST',
      timestamp: 'TEST',
      transaction_id: 'TEST',
      user_id: userId,
      signature: 'TEST',
      key_id: 'TEST',
    });
    await fetch(`https://your-staging-ssv-endpoint?${params.toString()}`);
  } catch (err) {
    console.error(err);
  }
});