앱 오프닝 광고

앱 오프닝 광고는 앱 로드 화면에서 수익을 올리려는 게시자를 위해 개발된 특별한 광고 형식입니다. 앱 오프닝 광고는 언제든지 닫을 수 있으며, 사용자가 앱을 포그라운드로 가져올 때 표시되도록 설계되었습니다.

앱 오프닝 광고는 사용자가 어떤 앱을 사용 중인지 알 수 있도록 작은 브랜딩 영역을 자동으로 표시합니다. 앱 오프닝 광고의 예는 다음과 같습니다.

기본 요건

  • 시작 가이드에 따라 필요한 과정을 완료합니다.
  • Unity 플러그인 7.1.0 이상

항상 테스트 광고로 테스트

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

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

/6499/example/app-open

구현

앱 오프닝 광고를 통합하는 기본 단계는 아래와 같습니다.

  1. 유틸리티 클래스 만들기
  2. 앱 오프닝 광고 로드
  3. 앱 오프닝 광고 이벤트 수신
  4. 광고 만료 고려
  5. 앱 상태 이벤트 수신
  6. 앱 오프닝 광고 표시
  7. 앱 오프닝 광고 정리
  8. 다음 앱 오프닝 광고 미리 로드

유틸리티 클래스 만들기

광고를 로드할 새 클래스(AppOpenAdController)를 만듭니다. 이 클래스는 플랫폼별로 로드된 광고 및 광고 단위 ID를 추적하는 인스턴스 변수를 관리합니다.

using System;
using UnityEngine;
using GoogleMobileAds.Api;
using GoogleMobileAds.Common;

/// <summary>
/// Demonstrates how to use the Google Mobile Ads app open ad format.
/// </summary>
[AddComponentMenu("GoogleMobileAds/Samples/AppOpenAdController")]
public class AppOpenAdController : MonoBehaviour
{

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

    public bool IsAdAvailable
    {
        get
        {
            return _appOpenAd != null;
        }
    }

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

    /// <summary>
    /// Loads the app open ad.
    /// </summary>
    public void LoadAppOpenAd()
    {
    }

    /// <summary>
    /// Shows the app open ad.
    /// </summary>
    public void ShowAppOpenAd()
    {
    }
}

앱 오프닝 광고 로드

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


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

  private AppOpenAd appOpenAd;

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

      Debug.Log("Loading the app open ad.");

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

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

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

              appOpenAd = ad;
              RegisterEventHandlers(ad);
          });
  }

앱 오프닝 광고 이벤트 수신

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

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

광고 만료 고려

만료된 광고가 게재되지 않도록 하려면 광고가 로드된 후 경과한 시간을 확인하는 메서드를 AppOpenAdController에 추가합니다. 그런 다음 이 메서드를 이용해 광고가 여전히 유효한지 확인하세요.

앱 오프닝 광고의 제한 시간은 4시간입니다. _expireTime 변수의 로드 시간을 캐시합니다.

// send the request to load the ad.
AppOpenAd.Load(_adUnitId, adRequest,
    (AppOpenAd ad, LoadAdError error) =>
    {
        // If the operation failed, an error is returned.
        if (error != null || ad == null)
        {
            Debug.LogError("App open ad failed to load an ad with error : " +
                            error);
            return;
        }

        // If the operation completed successfully, no error is returned.
        Debug.Log("App open ad loaded with response : " + ad.GetResponseInfo());

        // App open ads can be preloaded for up to 4 hours.
        _expireTime = DateTime.Now + TimeSpan.FromHours(4);

        _appOpenAd = ad;
    });

IsAdAvailable 속성을 업데이트하여 _expireTime을 통해 로드된 광고가 여전히 유효한지 확인하세요.

public bool IsAdAvailable
{
    get
    {
        return _appOpenAd != null
               && _appOpenAd.IsLoaded()
               && DateTime.Now < _expireTime;
    }
}

앱 상태 이벤트 수신

AppStateEventNotifier를 사용하여 애플리케이션 포그라운드 및 백그라운드 이벤트를 수신 대기합니다. 이 클래스는 애플리케이션이 포그라운드 또는 백그라운드에서 실행될 때마다 AppStateChanged 이벤트를 발생시킵니다.

private void Awake()
{
    // Use the AppStateEventNotifier to listen to application open/close events.
    // This is used to launch the loaded ad when we open the app.
    AppStateEventNotifier.AppStateChanged += OnAppStateChanged;
}

private void OnDestroy()
{
    // Always unlisten to events when complete.
    AppStateEventNotifier.AppStateChanged -= OnAppStateChanged;
}

AppState.Foreground 상태를 처리하고 IsAdAvailabletrue이면 ShowAppOpenAd()를 호출하여 광고를 표시합니다.

private void OnAppStateChanged(AppState state)
{
    Debug.Log("App State changed to : "+ state);

    // if the app is Foregrounded and the ad is available, show it.
    if (state == AppState.Foreground)
    {
        if (IsAdAvailable)
        {
            ShowAppOpenAd();
        }
    }
}

앱 오프닝 광고 표시

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

/// <summary>
/// Shows the app open ad.
/// </summary>
public void ShowAppOpenAd()
{
    if (appOpenAd != null && appOpenAd.CanShowAd())
    {
        Debug.Log("Showing app open ad.");
        appOpenAd.Show();
    }
    else
    {
        Debug.LogError("App open ad is not ready yet.");
    }
}

앱 오프닝 광고 정리

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

appOpenAd.Destroy();

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

다음 앱 오프닝 광고 미리 로드

AppOpenAd는 일회용 객체입니다. 즉, 앱 오프닝 광고가 표시된 후에는 이 객체를 다시 사용할 수 없습니다. 앱 오프닝 광고를 추가로 요청하려면 새 AppOpenAd 객체를 만들어야 합니다.

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

private void RegisterReloadHandler(AppOpenAd ad)
{
    ...
    // Raised when the ad closed full screen content.
    ad.OnAdFullScreenContentClosed += ()
    {
        Debug.Log("App open ad full screen content closed.");

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

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

콜드 스타트 및 로드 화면

지금까지 이 문서에서는 메모리에 정지된 앱을 사용자가 포그라운드로 가져올 때만 앱 오프닝 광고를 게재한다고 가정했습니다. '콜드 스타트'는 앱이 실행되었지만 이전에 메모리에서 정지되지 않은 경우에 발생합니다.

콜드 스타트의 예로는 사용자가 앱을 처음으로 열 때가 있습니다. 콜드 스타트를 사용하면 즉시 표시할 수 있도록 이전에 로드한 앱 오프닝 광고가 없습니다. 광고를 요청한 후 광고를 다시 수신하는 시점까지 지연이 발생하면 사용자가 맥락에서 벗어난 광고를 보고 당혹감을 느끼기 전에 앱을 잠시 사용할 수 있는 상황이 발생할 수 있습니다. 이는 불량 사용자 환경이기 때문에 피해야 합니다.

콜드 스타트 시 앱 오프닝 광고를 사용하는 가장 좋은 방법은 로드 화면을 사용하여 게임 또는 앱 애셋을 로드하고 로드 화면에서만 광고를 표시하는 것입니다. 앱 로드가 완료되고 사용자에게 앱의 주요 콘텐츠가 표시된 경우에는 광고를 표시하지 마세요.

권장사항

앱 오프닝 광고를 사용하면 앱이 처음 실행될 때나 앱이 전환될 때 앱의 로드 화면에서 수익을 창출할 수 있습니다. 하지만 사용자가 앱을 재미있게 사용할 수 있도록 다음 권장사항을 염두에 두는 것이 중요합니다.

  • 사용자가 앱을 몇 번 사용한 후에 첫 앱 오프닝 광고를 게재하세요.
  • 사용자가 앱이 로드되기를 기다리는 동안 앱 오프닝 광고를 표시합니다.
  • 앱 오프닝 광고 아래에 로드 화면이 있고 광고가 닫히기 전에 화면 로드가 완료되면 OnAdDidDismissFullScreenContent 이벤트 핸들러에서 로드 화면을 닫습니다.
  • iOS 플랫폼에서 AppStateEventNotifierAppStateEventClient GameObject를 인스턴스화합니다. 이벤트가 실행되려면 이 GameObject가 필요하므로 삭제하지 마세요. GameObject가 소멸되면 이벤트 실행이 중지됩니다.

추가 리소스