AdMob (ADX v2.4.0 이상)

ADX Unity Plugin 버전 v2.4.0 이상에서 AdMob 보상 광고를 로드 및 표시하는 방법에 대해서 설명합니다.

1. 기본 요건

  • ADX Unity SDK를 프로젝트에 추가합니다.

  • Rewarded Ad용으로 발급받은 AdMob Ad Unit ID를 사용합니다.

  • 광고를 요청하기 전에 SDK 초기화를 먼저 진행합니다.

    • SDK 초기화는 앱 실행 시 한 번만 호출하여 주시고, 광고 요청은 초기화가 완료된 후에 이뤄져야 합니다.

  • Unity > Assets > Google Mobile Ads > Settings를 선택하여 각 필드에 Android 및 iOS App ID를 입력합니다.

2. 구현

보상 광고 로드에 시간이 걸릴 수 있으니, 미리 로드 해두신 다음 사용하시는 것을 권장드립니다.

1) Android와 iOS 모두 배포된 경우 플랫폼 별로 발급받은 Ad Unit ID를 입력합니다.

#if UNITY_ANDROID
    string admobRewardedAdUnitID = "<ANDROID_ADMOB_REWARDED_AD_UNIT_ID>";
#elif UNITY_IOS
    string admobRewardedAdUnitID = "<IOS_ADMOB_REWARDED_AD_UNIT_ID>";
#endif

2) 광고 로드에 사용되는 AdRequest 객체 생성 후, RewardedAd 클래스의 정적 메소드 'Load' 를 이용하여 광고를 로드 합니다.

GDPR 관련 규정을 준수하는 경우, 사용자가 개인정보 활용 및 수집을 거부한 상태(2)일 때 AdRequestExtras 딕셔너리에 "npa" 키에 "1"를 추가합니다.

using AdxUnityPlugin;
using GoogleMobileAds.Api;
...
private GoogleMobileAds.Api.RewardedAd admobRewardedAd;
...

void LoadAdmobRewardedAd()
{ 
    // Create our request used to load the ad.       
    AdRequest adRequest = new AdRequest();
    if (ADXGDPRManager.GetConsentState() == 2) {
        // Extra parameters to be sent in the ad request.
        adRequest.Extras["npa"] = "1";
    }

    // Load a rewarded ad
    GoogleMobileAds.Api.RewardedAd.Load(
        admobRewardedAdUnitID, 
        adRequest, (GoogleMobileAds.Api.RewardedAd ad, LoadAdError loadError) => {
            if (loadError != null){
                Debug.Log("Admob Rewarded ad failed to load with error: " 
                + loadError.GetMessage());
                return;
            } else if (ad == null){
                Debug.Log("Admob Rewarded ad failed to load.");
                return;
            }
            Debug.Log("Admob Rewarded ad loaded.");
            admobRewardedAd = ad;
    });
}

3) 광고 로드에 성공하면, 광고 표시와 관련된 이벤트를 수신 받기 위해서 이벤트 핸들러를 등록합니다.

...
private GoogleMobileAds.Api.RewardedAd admobRewardedAd;
...

void LoadAdmobRewardedAd()
{        
    ...
    // Load a rewarded ad
    GoogleMobileAds.Api.RewardedAd.Load(
        admobRewardedAdUnitId, 
        adRequest, (GoogleMobileAds.Api.RewardedAd ad, LoadAdError loadError) => {
            ...
            admobRewardedAd = ad;
            // Register to ad events to extend functionality.
            RegisterEventHandlers(ad);
    });
}

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

유저가 광고 보상을 획득하면, OnAdPaid 이벤트 핸들러가 호출됩니다. 이 핸들러에서 유저에게 제공할 보상과 관련된 코드를 추가합니다. OnAdPaid 이벤트가 수신되지 않으면, 애드몹 대쉬보드에 로그인 후, 아래 경로로 이동하여 "노출 수준 광고 수익" 이 활성화 되어 있는지 확인하십시오. 애드몹 대쉬보드 > 설정 > 계정 정보 > 노출 수준 광고 수익

이전 광고가 닫힌 직후에 다음 보상형 광고가 로드될 수 있도록 OnAdFullScreenContentClosed 핸들러에서 다른 보상형 광고를 로드하는 것이 좋습니다.

4) CanShowAd 메소드로 광고를 표시할 수 있는 지 확인 후, Show 메소드로 광고를 표시합니다.

void ShowAdmobRewardedAd()
{
    if (admobRewardedAd != null && admobRewardedAd.CanShowAd()){
        admobRewardedAd.Show((Reward reward) => {
            Debug.Log("Admob Rewarded ad granted a reward: " + reward.Amount);
        });
    } else{
        Debug.Log("Admob Rewarded ad cannot be shown.");
    }
}

3. 타겟팅

광고 요청 시 타겟팅 정보를 설정할 수 있습니다. 필요에 따라 구현해주세요.

1) 아동 대상 설정 (아동 온라인 개인정보 보호법(COPPA))

RequestConfiguration requestConfiguration = new RequestConfiguration {
    TagForChildDirectedTreatment = TagForChildDirectedTreatment.True
};
MobileAds.SetRequestConfiguration(requestConfiguration);

2) 광고 콘텐츠 필터링

MobileAds.SetRequestConfiguration(requestConfiguration);
2) 광고 콘텐츠 필터링
RequestConfiguration requestConfiguration = new RequestConfiguration {
    MaxAdContentRating = MaxAdContentRating.G
};
MobileAds.SetRequestConfiguration(requestConfiguration);

4. 테스트 기기 등록

개발 중 상용 광고 키로 광고를 테스트하려는 경우 아래 단계에 따라 테스트 기기를 등록 후 사용해주시기 바랍니다.

테스트 기기 미등록 상태로 테스트할 경우 계정이 정지될 수 있습니다.

1) ADXLibrary를 적용 후 광고를 로드하는 코드가 삽입된 상태로 실행해주시면 콘솔에서 해당 로그를 확인하실 수 있습니다.

 I/Ads: Use RequestConfiguration.Builder
  .setTestDeviceIds(Arrays.asList("33BE2250B43518CCDA7DE426D04EE231"))
to get test ads on this device."

2) 출력된 Device ID를 복사하여 아래와 같이 SetTestDeviceIds() 를 호출하여 테스트 기기를 등록해주시면 됩니다.

앱을 출시하기 전에 테스트 기기를 설정하는 코드를 반드시 삭제하세요.

List<string> deviceIds = new List<string>();
deviceIds.Add("33BE2250B43518CCDA7DE426D04EE231");
deviceIds.Add("2077ef9a63d2b398840261c8221a0c9b");
RequestConfiguration requestConfiguration = new RequestConfiguration
    .Builder()
    .SetTestDeviceIds(deviceIds)
    .build();

MobileAds.SetRequestConfiguration(requestConfiguration);

Last updated