전면 광고

전면 광고는 호스트 앱의 인터페이스를 완전히 가리는 전체 화면 광고입니다. 게임에서 다음 레벨로 넘어갈 때처럼 앱 이용이 잠시 중단될 때 자연스럽게 광고가 게재됩니다. 앱에서 전면 광고가 표시될 때 사용자는 광고를 탭하여 도착 페이지로 이동하거나 광고를 닫고 앱으로 돌아갈 수 있습니다.

이 가이드에는 전면 광고를 Unity 앱에 통합하는 방법이 나와 있습니다.

기본 요건

항상 테스트 광고로 테스트

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

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

/6499/example/interstitial

모바일 광고 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.
        });
    }
}

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

구현

전면 광고를 통합하는 기본 단계는 다음과 같습니다.

  1. 전면 광고 로드
  2. 전면 광고 표시
  3. 전면 광고 이벤트 수신
  4. 전면 광고 정리
  5. 다음 전면 광고 미리 로드

전면 광고 로드

전면 광고는 InterstitialAd 클래스의 정적 Load() 메서드를 통해 로드됩니다. 로드 메서드에는 광고 단위 ID, AdManagerAdRequest 객체, 광고 로드에 성공하거나 실패할 때 호출되는 완료 핸들러가 필요합니다. 로드된 AdManagerInterstitialAd 객체는 완료 핸들러의 매개변수로 제공됩니다. 아래는 AdManagerInterstitialAd를 로드하는 방법의 예입니다.


  // This ad unit is configured to always serve test ads.
  private string _adUnitId = "/6499/example/interstitial";

  private InterstitialAd _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 AdManagerAdRequest();

      // send the request to load the ad.
      AdManagerInterstitialAd.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;
          });
  }

전면 광고 표시

로드된 전면 광고를 표시하려면 AdManagerInterstitialAd 인스턴스에서 Show() 메서드를 호출합니다. 광고는 로드당 한 번 표시될 수 있습니다. CanShowAd() 메서드를 사용하여 광고를 게재할 준비가 되었는지 확인합니다.

/// <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.");
    }
}

전면 광고 이벤트 수신

광고의 작동 방식을 추가로 맞춤설정하려는 경우 광고 수명 주기에서 여러 이벤트에 연결하면 됩니다. 아래와 같이 대리자를 등록하여 이러한 이벤트를 수신합니다.

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);
    };
}

전면 광고 정리

AdManagerInterstitialAd 지정이 끝나면 참조를 삭제하기 전에 Destroy() 메서드를 호출해야 합니다.

_interstitialAd.Destroy();

이렇게 하면 플러그인이 객체를 더 이상 사용하지 않으며 객체가 점유하는 메모리를 회수할 수 있음을 알립니다. 이 메서드를 호출하지 않으면 메모리 누수가 발생합니다.

다음 전면 광고 미리 로드

전면 광고는 일회용 객체입니다. 즉, 전면 광고가 표시된 후에는 이 객체를 다시 사용할 수 없습니다. 다른 전면 광고를 요청하려면 새 AdManagerInterstitialAd 객체를 만드세요.

다음 노출 기회에 대한 전면 광고가 게재되도록 OnAdFullScreenContentClosed 또는 OnAdFullScreenContentFailed 광고 이벤트가 발생한 후에 전면 광고를 미리 로드합니다.

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();
    };
}

앱 이벤트

앱 이벤트를 사용하면 앱 코드에 메시지를 전송하는 광고를 만들 수 있습니다. 그러면 앱에서 이러한 메시지를 기반으로 작업을 수행할 수 있습니다.

AppEvent를 사용하여 Ad Manager 관련 앱 이벤트를 수신할 수 있습니다. 이러한 이벤트는 로드가 호출되기 전을 포함해 광고의 수명 주기 동안 언제든지 발생할 수 있습니다.

namespace GoogleMobileAds.Api.AdManager;

/// The App event message sent from the ad.
public class AppEvent
{
    // Name of the app event.
    string Name;
    // Argument passed from the app event.
    string Value;
}

OnAppEventReceived는 광고에서 앱 이벤트가 발생하면 발생합니다. 다음은 코드에서 이 이벤트를 처리하는 방법을 보여주는 예입니다.

_interstitialAd.OnAppEventReceived += (AppEvent args) =>
{
    Debug.Log($"Received app event from the ad: {args.Name}, {args.Value}.");
};

다음은 색상 이름이 적용된 앱 이벤트에 따라 앱의 배경색을 변경하는 방법의 예입니다.

_interstitialAd.OnAppEventReceived += (AppEvent args) =>
{
  if (args.Name == "color")
  {
    Color color;
    if (ColorUtility.TryParseColor(arg.Value, out color))
    {
      gameObject.GetComponent<Renderer>().material.color = color;
    }
  }
};

다음은 색상 앱 이벤트를 전송하는 해당 광고 소재입니다.

<html>
<head>
  <script src="//www.gstatic.com/afma/api/v1/google_mobile_app_ads.js"></script>
  <script>
    document.addEventListener("DOMContentLoaded", function() {
      // Send a color=green event when ad loads.
      admob.events.dispatchAppEvent("color", "green");

      document.getElementById("ad").addEventListener("click", function() {
        // Send a color=blue event when ad is clicked.
        admob.events.dispatchAppEvent("color", "blue");
      });
    });
  </script>
  <style>
    #ad {
      width: 320px;
      height: 50px;
      top: 0px;
      left: 0px;
      font-size: 24pt;
      font-weight: bold;
      position: absolute;
      background: black;
      color: white;
      text-align: center;
    }
  </style>
</head>
<body>
  <div id="ad">Carpe diem!</div>
</body>
</html>

권장사항

전면 광고가 앱에 적합한 광고 유형인지 판단합니다.
전면 광고는 자연스러운 전환 지점이 있는 앱에서 가장 효과적입니다. 이러한 지점은 이미지 공유, 게임 레벨 달성 등 앱 내에서 작업이 완료되는 시점에 생성됩니다. 앱 흐름에서 전면 광고를 가장 효과적으로 표시하기 위한 지점과 사용자가 어떻게 반응할지 고려해야 합니다.
전면 광고를 표시할 때 작업을 일시중지합니다.
텍스트, 이미지, 동영상 등 다양한 유형의 전면 광고가 있습니다. 앱에서 전면 광고를 표시할 때는 광고에서 리소스를 활용할 수 있도록 일부 리소스의 사용을 중지해야 합니다. 예를 들어 전면 광고를 표시하도록 호출할 때 앱에서 재생되는 오디오 출력을 일시중지해야 합니다. 사용자가 광고와의 상호작용을 마칠 때 호출할 수 있는 OnAdFullScreenContentClosed() 이벤트를 통해 사운드 재생을 재개할 수 있습니다. 또한 광고가 표시되는 동안에는 게임 루프와 같은 강도 높은 계산 작업을 잠시 중단하는 것이 좋습니다. 이렇게 하면 그래픽이 느려지거나 응답이 없는 현상 또는 동영상 끊김 등의 불편을 겪지 않습니다.
광고를 과도하게 게재하면 안 됩니다.
앱에 전면 광고를 더 많이 게재할수록 수익이 늘어난다고 생각할 수 있겠지만, 이렇게 하면 사용자 환경이 악화되고 클릭률이 떨어지기도 합니다. 사용자의 원활한 앱 사용에 지장을 주지 않는 범위에서 게재 빈도를 조절하시기 바랍니다.

추가 리소스