전면 광고

전면 광고는 호스트 앱의 인터페이스를 가리는 전체 화면 광고입니다. 일반적으로 앱 이용 중 자연스러운 전환 시점에 표시됩니다. 예를 들어 게임에서 다음 레벨로 넘어갈 때 멈출 때처럼 말이죠 앱에서 전면 광고가 표시되는 경우 사용자는 광고를 탭하여 닫고 앱으로 돌아가세요

이 가이드에서는 Unity 앱에 전면 광고를 통합하는 방법을 설명합니다.

기본 요건

항상 테스트 광고로 테스트

다음 샘플 코드에는 요청에 사용할 수 있는 광고 단위 ID가 포함되어 있습니다. 테스트 광고 테스트 광고를 반환하도록 특별히 구성된 경우 만들기 때문에 안전하게 사용할 수 있습니다.

하지만 광고 단위를 직접 만들었으며 Ad Manager 웹 인터페이스를 앱에서 사용할 ID를 확인하고 기기를 테스트로 명시적으로 구성하세요. 기기에서 있습니다.

/6499/example/interstitial

모바일 광고 SDK 초기화

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

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. 다음 전면 광고 미리 로드

전면 광고 로드

전면 광고는Load() InterstitialAd 클래스. 로드 메서드에는 광고 단위 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;
          });
  }

전면 광고 표시

로드된 전면 광고를 표시하려면Show() AdManagerInterstitialAd 인스턴스. 광고는 다음 기간당 한 번 게재될 수 있습니다. 있습니다. 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() 이벤트에서 사운드 재생을 다시 시작할 수 있습니다. 사용자가 광고와의 상호작용을 마치면 호출될 수 있습니다. 포함 또한 게임 루프가 발생할 수 있습니다. 이렇게 하면 사용자가 느리거나 응답하지 않는 그래픽 또는 동영상 끊김 등의 문제가 있을 수 있습니다.
사용자에게 광고를 지나치게 많이 게재하지 않습니다.
앱에 게재되는 전면 광고의 게재빈도가 늘어나는 것처럼 보일 수 있지만 이용 만족도가 떨어질 수 있으므로 클릭률을 줄일 수 있습니다 사용자가 너무 자주 더 이상 앱 사용을 즐길 수 없다고 알립니다.
를 통해 개인정보처리방침을 정의할 수 있습니다.

추가 리소스