보상형 전면 광고 (베타)

보상형 전면 광고는 게재되는 광고에 대해 보상을 제공하는 인센티브형 광고 형식입니다. 자연스러운 앱 전환 중에 자동으로 작동합니다. 보상형 광고와 달리 사용자는 선택해야 합니다.

기본 요건

항상 테스트 광고로 테스트

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

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

Android

ca-app-pub-3940256099942544/5354046379

iOS

ca-app-pub-3940256099942544/6978759866

모바일 광고 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. [선택사항] 서버 측 확인 (SSV) 콜백 확인
  3. 리워드 콜백으로 보상형 전면 광고 표시
  4. 보상형 전면 광고 이벤트 수신
  5. 보상형 전면 광고 정리
  6. 다음 보상형 전면 광고 미리 로드

보상형 전면 광고 로드

보상형 전면 광고는 정적 Load()를 사용하여 로드됩니다. RewardedInterstitialAd 클래스의 메서드 로드 메서드에는 광고가 필요합니다. 단위 ID, AdRequest 객체, 완료 광고 로드에 성공하거나 실패할 때 호출되는 핸들러입니다. 로드된 완료 시 RewardedInterstitialAd 객체가 매개변수로 제공됩니다. 처리됩니다. 아래 예는 RewardedInterstitialAd를 로드하는 방법을 보여줍니다.


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

  private RewardedInterstitialAd _rewardedInterstitialAd;

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

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

      // create our request used to load the ad.
      var adRequest = new AdRequest();
      adRequest.Keywords.Add("unity-admob-sample");

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

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

              _rewardedInterstitialAd = ad;
          });
  }

[선택사항] 서버 측 확인 (SSV) 콜백 확인

서버 측 확인에서 추가 데이터가 필요한 앱 콜백은 보상형 전면 광고의 맞춤 데이터 기능을 사용해야 합니다. 보상형 광고 객체에 설정된 모든 문자열 값은 custom_data 쿼리 매개변수를 지정합니다. 맞춤 데이터 값이 설정되지 않은 경우 custom_data 쿼리 매개변수 값은 SSV 콜백에 포함되지 않습니다.

다음 코드 샘플은 보상형 전면 광고가 로드됩니다.

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

        // If the operation completed successfully, no error is returned.
        Debug.Log("Rewarded interstitial ad loaded with response : " +
                   ad.GetResponseInfo());
        
        // Create and pass the SSV options to the rewarded ad.
        var options = new ServerSideVerificationOptions
                              .Builder()
                              .SetCustomData("SAMPLE_CUSTOM_DATA_STRING")
                              .Build()
        ad.SetServerSideVerificationOptions(options);
        
});

맞춤 리워드 문자열을 설정하려면 있습니다.

리워드 콜백으로 보상형 전면 광고 표시

광고를 표시할 때 보상을 처리할 콜백을 제공해야 합니다. 있습니다. 광고는 로드당 한 번만 게재될 수 있습니다. CanShowAd() 메서드를 사용하여 다음을 수행합니다. 확인해야 합니다

다음 코드는 보상형 광고를 게재하는 데 가장 적합한 메서드를 나타냅니다. 전면 광고

public void ShowRewardedInterstitialAd()
{
    const string rewardMsg =
        "Rewarded interstitial ad rewarded the user. Type: {0}, amount: {1}.";

    if (rewardedInterstitialAd != null && rewardedInterstitialAd.CanShowAd())
    {
        rewardedInterstitialAd.Show((Reward reward) =>
        {
            // TODO: Reward the user.
            Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
        });
    }
}

보상형 전면 광고 이벤트 수신

광고의 작동 방식을 추가로 맞춤설정하려는 경우 사용합니다. 대리자를 등록하여 이러한 이벤트 수신 변경할 수 있습니다.

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

보상형 전면 광고 정리

RewardedInterstitialAd 사용을 마쳤으면 Destroy() 메서드를 호출하면 됩니다.

_rewardedInterstitialAd.Destroy();

이렇게 하면 플러그인이 더 이상 사용되지 않는다고 플러그인에 알리고 다시 확보할 수 있습니다. 이 메서드를 호출하지 못하면 메모리 누수가 발생합니다.

다음 보상형 전면 광고 미리 로드

RewardedInterstitialAd는 일회용 객체입니다. 즉, 리워드가 전면 광고가 표시되는 경우 해당 객체는 다시 사용할 수 없습니다. 다른 URL 요청 보상형 전면 광고를 사용하려면 새 RewardedInterstitialAd을(를) 로드해야 합니다. 객체를 지정합니다.

다음 노출 기회에 대한 보상형 전면 광고를 준비하려면 OnAdFullScreenContentClosed 또는 OnAdFullScreenContentFailed 광고 이벤트가 발생합니다.

private void RegisterReloadHandler(RewardedInterstitialAd ad)
{
    // Raised when the ad closed full screen content.
    ad.OnAdFullScreenContentClosed += ()
    {
        Debug.Log("Rewarded interstitial ad full screen content closed.");

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

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

추가 리소스