本文へ移動

テスト

開発中はテスト広告を使い、広告主への課金やアカウントの無効トラフィック判定を避けます。デモ広告ユニットとテストデバイスは Google のテスト広告ガイド(Android / iOS)を見てください。

このプラグインでは、そのデモユニットを使うか、initialize でデバイスを登録できます。

デモ広告ユニット

Google は常にテスト広告を返す デモ広告ユニット を提供しています。開発中はこれを優先してください。

バナー、インタースティシャル、リワード、リワード付きインタースティシャルでは isTesting: true も使えます。アプリ起動時広告に isTesting はないので、adId にデモ広告ユニットを渡します。

テストデバイス

実機で本番に近い広告を、無効トラフィックにせずリクエストするには、AdMob.initialize() でデバイスを登録します。

await AdMob.initialize({
  testingDevices: ['YOUR_TEST_DEVICE_ID'],
  initializeForTesting: true,
});

method initialize(...)

Initializes the Google Mobile Ads SDK.

initialize(options?: AdMobInitializationOptions | undefined) => Promise<void>

interface AdMobInitializationOptions

Prop Type Description Default Since
testingDevices string[] Device IDs to register as test devices when {@link AdMobInitializationOptions.initializeForTesting} is true. Requests from registered devices receive test ads and do not generate invalid traffic. 1.2.0
initializeForTesting boolean Whether to register {@link AdMobInitializationOptions.testingDevices} as test devices. false 1.2.0
tagForChildDirectedTreatment boolean For purposes of the Children's Online Privacy Protection Act (COPPA), there is a setting called tagForChildDirectedTreatment. 3.1.0
tagForUnderAgeOfConsent boolean When using this feature, a Tag For Users under the Age of Consent in Europe (TFUA) parameter will be included in all future ad requests. 3.1.0
maxAdContentRating MaxAdContentRating The maximum ad content rating applied to all ad requests. Ads with a higher rating are excluded. 3.1.0

デバイス ID は、最初の広告リクエスト後のネイティブログに出ます。

  • Android: Logcat の Ads タグ(Use RequestConfiguration.Builder.setTestDeviceIds(...))。
  • iOS: Xcode コンソール(To get test ads on this device, set:)。

Google の テストデバイスの有効化 も参照してください。

同意のデバッグ地域

実機では debugGeography を設定し、デバイス ID を testDeviceIdentifiers に含めます。EEA はデバイスが欧州経済領域にいるようにフォームを動かすので、GDPR メッセージをテストできます。登録済みテストデバイスでのみ使ってください。

import { AdMob, AdmobConsentDebugGeography } from '@capacitor-community/admob';

const consentInfo = await AdMob.requestConsentInfo({
  debugGeography: AdmobConsentDebugGeography.EEA,
  testDeviceIdentifiers: ['YOUR_TEST_DEVICE_ID'],
});

method requestConsentInfo(...)

Request user consent information

requestConsentInfo(options?: AdmobConsentRequestOptions | undefined) => Promise<AdmobConsentInfo>

interface AdmobConsentRequestOptions

Prop Type Description Default Since
debugGeography AdmobConsentDebugGeography Sets the debug geography to test the consent locally. 5.0.0
testDeviceIdentifiers string[] An array of test device IDs to allow. Note: On iOS, the ID may renew if you uninstall and reinstall the app. 5.0.0
tagForUnderAgeOfConsent boolean Set to true to provide the option for the user to accept being shown personalized ads. false 5.0.0

enum AdmobConsentDebugGeography

Member Value Description
DISABLED 0 Debug geography disabled.
EEA 1 Geography appears as in EEA for debug devices.
NOT_EEA 2 Geography appears as not in EEA for debug devices.
US 3 Geography appears as in regulated US state for debug devices.
OTHER 4 Geography appears as OTHER state for debug devices.

テスト用フォームで同意を拒否する(Manage → Confirm Choices)と、広告がロードされないことがあります。テスト環境では想定どおりで、本番でユーザーが同意したあとの挙動を示すものではありません。

resetConsentInfo() はテスト専用です。同意管理 を参照してください。

サーバーサイド検証

サーバーサイド検証(SSV)のコールバックは本番広告でのみ送られます。テスト広告は SSV エンドポイントに届きません。モックリクエストの例は リワード広告 を参照してください。