插页式广告

插页式广告属于全屏广告,会覆盖宿主应用的整个界面,通常展示在应用流程的自然过渡点上,例如,活动之间的切换处或游戏关卡之间的暂停时段中。当应用展示插页式广告时,用户可以选择点按该广告,进而访问其目标网址,也可以将其关闭,并返回应用。 阅读我们的案例研究

本指南介绍了如何将插页式广告植入到 Android 应用中。

前提条件

  • Google 移动广告 SDK 19.7.0 或更高版本。
  • 完成入门指南

务必用测试广告进行测试

在构建和测试应用时,请确保使用的是测试广告,而不是实际投放的广告。否则,可能会导致您的账号被中止。

对于 Android 插页式广告,加载测试广告最简便的方法就是使用下面的专用测试广告单元 ID:

ca-app-pub-3940256099942544/1033173712

该测试广告单元 ID 已经过专门配置,可确保每个请求返回的都是测试广告。您可以在自己应用的编码、测试和调试过程中随意使用该测试广告单元 ID。只需确保您会在发布应用前用自己的广告单元 ID 替换该测试广告单元 ID 即可。

如需详细了解移动广告 SDK 的测试广告如何运作,请参阅测试广告

加载广告

如需加载插页式广告,请调用 InterstitialAd 静态 load() 方法并传入 InterstitialAdLoadCallback,以接收加载的广告或任何可能的错误。请注意,与其他广告格式加载回调一样,InterstitialAdLoadCallback 会利用 LoadAdError 提供较高保真度的错误详情。

Java

InterstitialAd.load(
    this,
    AD_UNIT_ID,
    new AdRequest.Builder().build(),
    new InterstitialAdLoadCallback() {
      @Override
      public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
        Log.d(TAG, "Ad was loaded.");
        MyActivity.this.interstitialAd = interstitialAd;
      }

      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
        Log.d(TAG, loadAdError.getMessage());
        interstitialAd = null;
    });

Kotlin

InterstitialAd.load(
  this,
  AD_UNIT_ID,
  AdRequest.Builder().build(),
  object : InterstitialAdLoadCallback() {
    override fun onAdLoaded(ad: InterstitialAd) {
      Log.d(TAG, "Ad was loaded.")
      interstitialAd = ad
    }

    override fun onAdFailedToLoad(adError: LoadAdError) {
      Log.d(TAG, adError.message)
      interstitialAd = null
    }
  },
)

设置 FullScreenContentCallback

FullScreenContentCallback 处理与展示 InterstitialAd 相关的事件。在展示 InterstitialAd 之前,请务必按如下方式设置回调:

Java

interstitialAd.setFullScreenContentCallback(
    new FullScreenContentCallback() {
      @Override
      public void onAdDismissedFullScreenContent() {
        // Called when fullscreen content is dismissed.
        Log.d(TAG, "The ad was dismissed.");
        // Make sure to set your reference to null so you don't
        // show it a second time.
        MyActivity.this.interstitialAd = null;
      }

      @Override
      public void onAdFailedToShowFullScreenContent(AdError adError) {
        // Called when fullscreen content failed to show.
        Log.d(TAG, "The ad failed to show.");
        // Make sure to set your reference to null so you don't
        // show it a second time.
        MyActivity.this.interstitialAd = null;
      }

      @Override
      public void onAdShowedFullScreenContent() {
        // Called when fullscreen content is shown.
        Log.d(TAG, "The ad was shown.");
      }

      @Override
      public void onAdImpression() {
        // Called when an impression is recorded for an ad.
        Log.d(TAG, "The ad recorded an impression.");
      }

      @Override
      public void onAdClicked() {
        // Called when ad is clicked.
        Log.d(TAG, "The ad was clicked.");
      }
    });

Kotlin

interstitialAd?.fullScreenContentCallback =
  object : FullScreenContentCallback() {
    override fun onAdDismissedFullScreenContent() {
      // Called when fullscreen content is dismissed.
      Log.d(TAG, "Ad was dismissed.")
      // Don't forget to set the ad reference to null so you
      // don't show the ad a second time.
      interstitialAd = null
    }

    override fun onAdFailedToShowFullScreenContent(adError: AdError) {
      // Called when fullscreen content failed to show.
      Log.d(TAG, "Ad failed to show.")
      // Don't forget to set the ad reference to null so you
      // don't show the ad a second time.
      interstitialAd = null
    }

    override fun onAdShowedFullScreenContent() {
      // Called when fullscreen content is shown.
      Log.d(TAG, "Ad showed fullscreen content.")
    }

    override fun onAdImpression() {
      // Called when an impression is recorded for an ad.
      Log.d(TAG, "Ad recorded an impression.")
    }

    override fun onAdClicked() {
      // Called when ad is clicked.
      Log.d(TAG, "Ad was clicked.")
    }
  }

展示广告

插页式广告应在应用流程的自然停顿期间进行展示,例如游戏的不同关卡之间或用户完成一项任务之后,都是非常不错的展示时机。如需展示插页式广告,请使用 show() 方法。

Java

if (interstitialAd != null) {
  interstitialAd.show(this);
} else {
  Log.d(TAG, "The interstitial ad is still loading.");
}

Kotlin

interstitialAd?.show(this)

一些最佳做法

考虑插页式广告这种广告类型是否适合您的应用。
在具有自然过渡点的应用中,插页式广告的效果最好。此类过渡点通常存在于应用内的任务结束时,例如分享完图片或完成一个游戏关卡时。请务必考虑在应用流程的哪些时间点展示插页式广告,以及用户可能会以什么方式响应。
务必在展示插页式广告时暂停操作。
插页式广告类型多样,包括文字广告、图片广告和视频广告等。确保应用在展示插页式广告时,也会暂停使用某些资源,以便供广告使用,这一点十分重要。例如,当您发出展示插页式广告的调用后,请务必暂停应用产生的所有音频输出。
留出充足的加载时间。
确保在恰当的时间展示插页式广告十分重要,同样,确保用户无需等待广告加载也十分重要。在您打算调用 show() 前,请事先通过调用 load() 加载广告,这可确保应用在广告展示时间到来前完全加载插页式广告。
不要向用户展示太多广告。
虽然提高插页式广告在应用中的展示频次似乎是实现增收的好方法,但这么做也会影响用户体验并降低点击率。应确保用户不会频繁受到广告打扰,使他们可以充分享受到使用应用的乐趣。

源代码

GitHub 上的示例

成功案例

后续步骤