インタースティシャル広告は、ホストアプリのインターフェース上に全画面表示される広告です。通常は、次のアクティビティに移行する前や、ゲームレベルをクリアした後の合間など、アプリの操作中に画面が切り替わるタイミングで表示されます。アプリにインタースティシャル広告が表示された場合、ユーザーは広告をタップしてリンク先に移動するか、広告を閉じてアプリに戻るかを選択できます。 事例紹介をご覧ください。
このガイドでは、インタースティシャル広告を Android アプリに統合する方法について説明します。
前提条件
必ずテスト広告でテストする
アプリの開発とテストでは必ずテスト広告を使用し、配信中の実際の広告は使用しないでください。実際の広告を使用すると、アカウントが停止される可能性があります。
テスト広告を読み込む際は、次に示す Android インタースティシャル向けのテスト専用広告ユニット ID を使うと便利です。
ca-app-pub-3940256099942544/1033173712
この ID は、すべてのリクエストに対してテスト広告を返す特別な ID で、アプリのコーディング、テスト、デバッグで自由に使うことができます。なお、アプリを公開する前に、必ずテスト用 ID をご自身の広告ユニット ID に置き換えてください。
Google Mobile Ads SDK(ベータ版)のテスト広告の仕組みについて詳しくは、テスト広告をご覧ください。
広告を読み込む
インタースティシャル広告を読み込むには、InterstitialAd
の静的 load()
メソッドを呼び出して、AdLoadCallback<InterstitialAd>
を渡すと、読み込まれた広告または発生する可能性があるすべてのエラーを受け取ることができます。
Kotlin
import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback
import com.google.android.libraries.ads.mobile.sdk.common.AdRequest
import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError
import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError
import com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAd
import com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAdEventCallback
import com.google.android.libraries.ads.mobile.sdk.MobileAds
class InterstitialActivity : Activity() {
private var interstitialAd: InterstitialAd? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Load ads after you initialize Google Mobile Ads SDK (beta).
InterstitialAd.load(
AdRequest.Builder(AD_UNIT_ID).build(),
object : AdLoadCallback<InterstitialAd> {
override fun onAdLoaded(ad: InterstitialAd) {
// Interstitial ad loaded.
interstitialAd = ad
}
override fun onAdFailedToLoad(adError: LoadAdError) {
// Interstitial ad failed to load.
interstitialAd = null
}
},
)
}
companion object {
// Sample interstitial ad unit ID.
const val AD_UNIT_ID = "ca-app-pub-3940256099942544/1033173712"
}
}
Java
import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback;
import com.google.android.libraries.ads.mobile.sdk.common.AdRequest;
import com.google.android.libraries.ads.mobile.sdk.common.FullScreenContentError;
import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError;
import com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAd;
import com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAdEventCallback;
import com.google.android.libraries.ads.mobile.sdk.MobileAds;
class InterstitialActivity extends Activity {
// Sample interstitial ad unit ID.
private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/1033173712";
private InterstitialAd interstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load ads after you initialize Google Mobile Ads SDK (beta).
InterstitialAd.load(
new AdRequest.Builder(AD_UNIT_ID).build(),
new AdLoadCallback<InterstitialAd>() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
// Interstitial ad loaded.
AdLoadCallback.super.onAdLoaded(interstitialAd);
InterstitialActivity.this.interstitialAd = interstitialAd;
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError adError) {
// Interstitial ad failed to load.
AdLoadCallback.super.onAdFailedToLoad(adError);
interstitialAd = null;
}
}
);
}
}
InterstitialAdEventCallback を設定する
InterstitialAdEventCallback
は、InterstitialAd
の表示に関連するイベントを処理します。インタースティシャル広告を表示する前に、コールバックを以下のように設定してください。
Kotlin
// Listen for ad events.
interstitialAd?.adEventCallback =
object : InterstitialAdEventCallback {
override fun onAdShowedFullScreenContent() {
// Interstitial ad did show.
}
override fun onAdDismissedFullScreenContent() {
// Interstitial ad did dismiss.
interstitialAd = null
}
override fun onAdFailedToShowFullScreenContent(
fullScreenContentError: FullScreenContentError
) {
// Interstitial ad failed to show.
interstitialAd = null
}
override fun onAdImpression() {
// Interstitial ad did record an impression.
}
override fun onAdClicked() {
// Interstitial ad did record a click.
}
}
Java
// Listen for ad events.
interstitialAd.setAdEventCallback(
new InterstitialAdEventCallback() {
@Override
public void onAdShowedFullScreenContent() {
// Interstitial ad did show.
InterstitialAdEventCallback.super.onAdShowedFullScreenContent();
}
@Override
public void onAdDismissedFullScreenContent() {
// Interstitial ad did dismiss.
InterstitialAdEventCallback.super.onAdDismissedFullScreenContent();
interstitialAd = null;
}
@Override
public void onAdFailedToShowFullScreenContent(
@NonNull FullScreenContentError fullScreenContentError) {
// Interstitial ad failed to show.
InterstitialAdEventCallback.super.onAdFailedToShowFullScreenContent(
fullScreenContentError);
initerstitialAd = null;
}
@Override
public void onAdImpression() {
// Interstitial ad did record an impression.
InterstitialAdEventCallback.super.onAdImpression();
}
@Override
public void onAdClicked() {
// Interstitial ad did record a click.
InterstitialAdEventCallback.super.onAdClicked();
}
}
);
広告を表示する
インタースティシャル広告を表示するには、show()
メソッドを使用します。
Kotlin
// Show the ad.
interstitialAd?.show(this@InterstitialActivity)
Java
// Show the ad.
interstitialAd.show(InterstitialActivity.this);
ベスト プラクティス
- インタースティシャル広告が自分のアプリに適しているかどうかをよく見極めましょう。
- インタースティシャル広告は、自然な移行ポイント(画面の切り替わりなど)があるアプリに適しています。 画像の共有やゲームレベルのクリアなど、アプリ内で特定のタスクが完了したタイミングがこうした切り替わりポイントになります。アプリのワークフローのどのタイミングでインタースティシャル広告を表示するか、それに対してユーザーがどのように反応しそうかをよく検討してください。
- インタースティシャル広告を表示する際には必ずアクションを一時停止しましょう。
- インタースティシャル広告には、テキスト、イメージ、動画など、さまざまな種類があります。アプリにインタースティシャル広告を表示する際は、一部のリソースの使用を停止して、広告でそのリソースを利用できるようにすることも重要です。たとえばインタースティシャル広告を呼び出して表示する際は、アプリの音声出力を一時停止します。
- 十分な読み込み時間を確保しましょう。
- インタースティシャル広告を適切なタイミングで表示することも大事ですが、それと同様に読み込みの待ち時間を短くすることも重要です。
show()
を呼び出す前にload()
を呼び出して広告の読み込みを事前に完了しておくと、表示の段階で待ち時間が発生しません。 - 過度に広告を表示しないよう注意しましょう。
- インタースティシャル広告の表示頻度を上げると増収につながる可能性がありますが、ユーザーの利便性が損なわれてクリック率が低下する可能性もあります。ユーザーがアプリを楽しめなくなるため、過度に頻繁に広告を表示するのは避けてください。
例
Google Mobile Ads SDK(ベータ版)の使用方法を示したサンプルアプリをダウンロードし、実行してください。