전면 광고

Interstitial ads are full-screen ads that cover the interface of their host app. They're typically displayed at natural transition points in the flow of an app, such as during the pause between levels in a game. When an app shows an interstitial ad, the user has the choice to either tap on the ad and continue to its destination or close it and return to the app. Case study.

This guide explains how to integrate interstitial ads into a Unity app.

Prerequisites

항상 테스트 광고로 테스트

아래 샘플 코드에는 테스트 광고 요청에 사용할 수 있는 광고 단위 ID가 포함되어 있습니다. 이 ID는 모든 요청에 대해 실제 광고가 아닌 테스트 광고를 반환하도록 구성되어서 안전하게 사용할 수 있습니다.

그러나AdMob 웹 인터페이스에 앱을 등록하고 앱에서 사용할 광고 단위 ID를 직접 만든 후에는 개발 중에 명시적으로 기기를 테스트 기기로 구성해야 합니다.

Android

ca-app-pub-3940256099942544/1033173712

iOS

ca-app-pub-3940256099942544/4411468910

모바일 광고 SDK 초기화

광고를 로드하기 전에 MobileAds.Initialize()를 호출하여 앱에서 모바일 광고 SDK를 초기화하도록 합니다. 이 작업은 앱 실행 시 한 번만 처리하면 됩니다.

using GoogleMobileAds;
using GoogleMobileAds.Api;

public class GoogleMobileAdsDemoScript : MonoBehaviour
{
    public void Start()
    {
        // Initialize the Google Mobile Ads SDK.
        MobileAds.Initialize((InitializationStatus initStatus) =>
        {
            // This callback is called once the MobileAds SDK is initialized.
        });
    }
}

미디에이션을 사용하는 경우 광고를 로드하기 전에 콜백이 발생할 때까지 기다려야 모든 미디에이션 어댑터가 초기화됩니다.

Implementation

The main steps to integrate interstitial ads are:

  1. Load the interstitial ad
  2. Show the interstitial ad
  3. Listen to interstitial ad events
  4. Clean up the interstitial ad
  5. Preload the next interstitial ad

Load the interstitial ad

Loading an interstitial ad is accomplished using the static Load() method on the InterstitialAd class. The load method requires an ad unit ID, an AdRequest object, and a completion handler which gets called when ad loading succeeds or fails. The loaded InterstitialAd object is provided as a parameter in the completion handler. The example below shows how to load an InterstitialAd.


  // These ad units are configured to always serve test ads.
#if UNITY_ANDROID
  private string _adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
  private string _adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
  private string _adUnitId = "unused";
#endif

  private _interstitialAd;

  /// <summary>
  /// Loads the interstitial ad.
  /// </summary>
  public void LoadInterstitialAd()
  {
      // Clean up the old ad before loading a new one.
      if (_interstitialAd != null)
      {
            _interstitialAd.Destroy();
            _interstitialAd = null;
      }

      Debug.Log("Loading the interstitial ad.");

      // create our request used to load the ad.
      var adRequest = new AdRequest();

      // send the request to load the ad.
      InterstitialAd.Load(_adUnitId, adRequest,
          (InterstitialAd ad, LoadAdError error) =>
          {
              // if error is not null, the load request failed.
              if (error != null || ad == null)
              {
                  Debug.LogError("interstitial ad failed to load an ad " +
                                 "with error : " + error);
                  return;
              }

              Debug.Log("Interstitial ad loaded with response : "
                        + ad.GetResponseInfo());

              _interstitialAd = ad;
          });
  }

Show the interstitial ad

To show a loaded interstitial ad, call the Show() method on the InterstitialAd instance. Ads may be shown once per load. Use the CanShowAd() method to verify that the ad is ready to be shown.

/// <summary>
/// Shows the interstitial ad.
/// </summary>
public void ShowInterstitialAd()
{
    if (_interstitialAd != null && _interstitialAd.CanShowAd())
    {
        Debug.Log("Showing interstitial ad.");
        _interstitialAd.Show();
    }
    else
    {
        Debug.LogError("Interstitial ad is not ready yet.");
    }
}

Listen to interstitial ad events

To further customize the behavior of your ad, you can hook into a number of events in the ad's lifecycle. Listen for these events by registering a delegate as shown below.

private void RegisterEventHandlers(InterstitialAd interstitialAd)
{
    // Raised when the ad is estimated to have earned money.
    interstitialAd.OnAdPaid += (AdValue adValue) =>
    {
        Debug.Log(String.Format("Interstitial ad paid {0} {1}.",
            adValue.Value,
            adValue.CurrencyCode));
    };
    // Raised when an impression is recorded for an ad.
    interstitialAd.OnAdImpressionRecorded += () =>
    {
        Debug.Log("Interstitial ad recorded an impression.");
    };
    // Raised when a click is recorded for an ad.
    interstitialAd.OnAdClicked += () =>
    {
        Debug.Log("Interstitial ad was clicked.");
    };
    // Raised when an ad opened full screen content.
    interstitialAd.OnAdFullScreenContentOpened += () =>
    {
        Debug.Log("Interstitial ad full screen content opened.");
    };
    // Raised when the ad closed full screen content.
    interstitialAd.OnAdFullScreenContentClosed += () =>
    {
        Debug.Log("Interstitial ad full screen content closed.");
    };
    // Raised when the ad failed to open full screen content.
    interstitialAd.OnAdFullScreenContentFailed += (AdError error) =>
    {
        Debug.LogError("Interstitial ad failed to open full screen content " +
                       "with error : " + error);
    };
}

Clean up the interstitial ad

When you are finished with an InterstitialAd, make sure to call the Destroy() method before dropping your reference to it:

_interstitialAd.Destroy();

This notifies the plugin that the object is no longer used and the memory it occupies can be reclaimed. Failure to call this method results in memory leaks.

Preload the next interstitial ad

Interstitial ads are a one-time-use object. This means once an interstitial ad is shown, the object can't be used again. To request another interstitial ad, create a new InterstitialAd object.

To prepare an interstitial ad for the next impression opportunity, preload the interstitial ad once the OnAdFullScreenContentClosed or OnAdFullScreenContentFailed ad event is raised.

private void RegisterReloadHandler(InterstitialAd interstitialAd)
{
    // Raised when the ad closed full screen content.
    interstitialAd.OnAdFullScreenContentClosed += ()
    {
        Debug.Log("Interstitial Ad full screen content closed.");

        // Reload the ad so that we can show another as soon as possible.
        LoadInterstitialAd();
    };
    // Raised when the ad failed to open full screen content.
    interstitialAd.OnAdFullScreenContentFailed += (AdError error) =>
    {
        Debug.LogError("Interstitial ad failed to open full screen content " +
                       "with error : " + error);

        // Reload the ad so that we can show another as soon as possible.
        LoadInterstitialAd();
    };
}

Best practices

Determine whether interstitial ads are the right type of ad for your app.
Interstitial ads work best in apps with natural transition points. The conclusion of a task within an app, such as sharing an image or completing a game level, creates such a point. Make sure you consider at which points in your app's flow to best display interstitial ads and how the user is likely to respond.
Pause the action when displaying an interstitial ad.
There are a number of different types of interstitial ads such as text, image, or video. It's important to make sure that when your app displays an interstitial ad, it also suspends its use of some resources to allow the ad to take advantage of them. For example, when you make the call to display an interstitial ad, be sure to pause any audio output being produced by your app. You can resume playing sounds in the OnAdFullScreenContentClosed() event, which can be invoked when the user has finished interacting with the ad. In addition, consider temporarily halting any intense computation tasks, such as a game loop, while the ad is being displayed. This ensures that the user doesn't experience slow or unresponsive graphics or stuttered video.
Don't flood the user with ads.
While increasing the frequency of interstitial ads in your app might seem like a great way to increase revenue, it can also degrade the user experience and lower click-through rates. Make sure that users aren't so frequently interrupted that they're no longer able to enjoy the use of your app.

Additional resources

* Sample use case