[GoogleMobileAds] Unity-Google-UMP-Check(GDPR)
2024년 1월 16일까지(참조:https://support.google.com/admob/answer/14189727?hl=ko) Admob을 사용하려면 유저에게 GDPR 동의를 받으라고 하는 것 같다.
그래서 Google에서 관련 SDK를 내놓은게 UMP(User Messaging Platform) SDK다.
----
Unity GoogleMobileAds에 UMP 적용하기 위해 찾아보니 누군가가 github에 정리해 놨길래 가져와서 적당히(?) 개조해서 내 GoogleMobileAdsManager에 추가 했다.
[Unity-Google-UMP-Check] https://github.com/TheBossaaa/Unity-Google-UMP-Check
기본적으로 위 소스만 적용하고 폰에서 실행해보면 아래와 같은 에러가 나온다.
[Error Code] GoogleMobileAds.Ump.Api.FormError
해당 에러는 GoogleMobileAds Dashboard에서 GDPR 관련 설정이 안돼 있어서 나오는 에러이다.
아래 Admob UMP Docs에서는 딱히 GoogleMobileAds Dashboard 관련 설정을 설명 안해놔서 모르고 넘어갈 수 있다.
Dashboard에 설정을 하자.
[FormError 관련 참조] https://github.com/googleads/googleads-mobile-unity/issues/2780
※ 추가적으로 Admob UMP Docs에 보면 Runtime에 GDPR 변경을 위한 버튼을 구현하는 샘플이 보인다.
법적으로 Runtime에 GDPR 변경을 해줘야 되는거면 버튼도 별도로 추가해줘야 될 것 같다.
[참조] https://github.com/googleads/googleads-mobile-unity/issues/2780
[GDPR 테스트]
GDPR 테스트 관련 소스가 들어있는데, Test Device Hashed Id를 넣으라고 돼있고, 실행해보면 Logcat에 뜬다고 돼 있는데 안떠서 찾아보니 아래와 같은 내용이 있다.
(난 현재 테스트 폰이 API 30이 안돼서 Test Device Hashed Id는 안넣어도 되는 것 같다.)
I also struggled with the same problem. The reason NOT_REQUIRED is always returned is that the test device ID has not been registered. DebugGeography does not apply to non-test devices. In my case, even if it is a basic Android emulator, I had to register the test device ID to resolve this issue. Your emulator's device ID is displayed in logcat as follows when ConsentInformation.requestConsentInfoUpdate is called.
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("xxxxxxxxx") to set this as a debug device.
EDIT: I did more tests. It requires a test device ID since Android API 30. Until API 29, it is not necessary to specify the test device ID. I'm not sure if this is only for my development environment.
[참조] https://stackoverflow.com/questions/68529268/ump-consentstatus-always-notrequired-when-testing
[GoogleMobileAdsManager에 추가된 GDPR 관련 UMP 소스]
using GoogleMobileAds.Ump.Api;
#region UMP(User Messaging Platform)
/// <summary>
/// Privacy(GDPR) 요청
/// </summary>
public void Request_Privacy_GDPR()
{
RequestConsentInfo();
}
///Summary
///Request Consent Information
///Warning: Ads can be preloaded by the Google Mobile Ads SDK or mediation partner SDKs
///upon calling MobileAds.Initialize(). If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags, such as tagForChildDirectedTreatment or tag_for_under_age_of_consent, or otherwise take action before loading ads.
///Ensure you do this before initializing the Google Mobile Ads SDK.
///Summary
void RequestConsentInfo()
{
Debug.Log("[UMP] RequestConsentInfo()");
// Set tag for under age of consent.
// Here false means users are not under age of consent.
ConsentRequestParameters request = new ConsentRequestParameters
{
TagForUnderAgeOfConsent = false,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogErrorFormat("[UMP][OnConsentInfoUpdated] {0}", consentError);
// UMP 동의 Error 시에도 초기화 진행[blueasa / 2024-03-15]
InitializeGoogleMobileAds();
return;
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
{
if (formError != null)
{
// Consent gathering failed.
UnityEngine.Debug.LogErrorFormat("[UMP][LoadAndShowConsentFormIfRequired] {0}", consentError);
// UMP 동의 Error 시에도 초기화 진행[blueasa / 2024-03-15]
InitializeGoogleMobileAds();
return;
}
// Consent has been gathered.
if (ConsentInformation.CanRequestAds())
{
// UMP 동의 이후 GoogleMobileAds 초기화[blueasa / 2023-12-14]
// GDPR 동의 했거나, EU가 아니어도 호출되기 때문에 여기서 초기화 함.
InitGoogleMobileAds();
}
});
}
/// <summary>
/// Privacy(GDPR) Button 활성화 여부 체크
/// (설정 창에 버튼 추가함)
/// </summary>
public bool CheckActivePrivacyButton()
{
bool bActive = false;
// EU인지 여부에 따라 버튼 활성화 체크 필요
#region ConsentInformation.PrivacyOptionsRequirementStatus
bActive = IsPrivacyOptionsRequirement();
#endregion
#region ConsentInformation.ConsentStatus
//bActive = IsConsentForGDPR();
#endregion
return bActive;
}
public bool IsPrivacyOptionsRequirement()
{
// [PrivacyOptionsRequirementStatus enum 참조]
// https://developers.google.com/admob/unity/reference/namespace/google-mobile-ads/ump/api#namespace_google_mobile_ads_1_1_ump_1_1_api_1a60f41ef4f7e14d5ae1fb5f23b7e0244b
//public enum PrivacyOptionsRequirementStatus
//{
// Unknown,
// NotRequired,
// Required
//}
bool bIsPrivacyOptionsRequirement = false;
// 개인정보 보호 옵션을 표시해야 하는지 여부
switch (ConsentInformation.PrivacyOptionsRequirementStatus)
{
// 개인정보 보호 옵션이 표시되어야 함.
case PrivacyOptionsRequirementStatus.Required:
bIsPrivacyOptionsRequirement = true;
break;
// 개인정보 보호 옵션은 표시할 필요가 없음.
case PrivacyOptionsRequirementStatus.NotRequired:
bIsPrivacyOptionsRequirement = false;
break;
// 개인 정보 보호 옵션 요구 사항 상태를 알 수 없음.
case PrivacyOptionsRequirementStatus.Unknown:
bIsPrivacyOptionsRequirement = false;
break;
default:
bIsPrivacyOptionsRequirement = false;
break;
}
return bIsPrivacyOptionsRequirement;
}
public bool IsConsentForGDPR()
{
// [ConsentStatus enum 참조]
// https://developers.google.com/admob/unity/reference/namespace/google-mobile-ads/ump/api#namespace_google_mobile_ads_1_1_ump_1_1_api_1aa83ad2ecf6f2a08c584b60cef06f5133
//ConsentStatus
//{
// Unknown = 0, // Unknown consent status.
// NotRequired = 1, // Consent not required.
// Required = 2, // User consent required but not yet obtained.
// Obtained = 3 // User consent obtained, personalized vs non-personalized undefined.
//}
bool bIsConsentForGDPR = false;
switch (ConsentInformation.ConsentStatus)
{
case ConsentStatus.Unknown: // 동의 상태를 알 수 없습니다.
case ConsentStatus.Required: // 사용자 동의가 필요하지만 아직 획득되지 않았습니다.
case ConsentStatus.NotRequired: // 동의가 필요하지 않습니다.
bIsConsentForGDPR = false;
break;
case ConsentStatus.Obtained: // 사용자 동의 획득, 개인화 및 비개인화 정의되지 않음.
bIsConsentForGDPR = true;
break;
}
return bIsConsentForGDPR;
}
/// <summary>
/// Privacy(GDPR) Button 클릭해서 GDPR 동의 창 띄우기
/// </summary>
public void OnClickPrivacyButton()
{
UpdatePrivacyButton();
}
void PrivacyButton()
{
//// Enable the privacy settings button.
//if (_privacyButton != null)
//{
// _privacyButton.onClick.AddListener(UpdatePrivacyButton);
// // Disable the privacy settings button by default.
// _privacyButton.interactable = false;
//}
}
private void UpdatePrivacyButton()
{
// Logic for updating privacy options
ShowPrivacyOptionsForm(); // You might want to call your method to show the privacy options form here
Debug.LogFormat("[UMP][UpdatePrivacyButton] Privacy button clicked!");
}
/// <summary>
/// Shows the privacy options form to the user.
/// </summary>
public void ShowPrivacyOptionsForm()
{
Debug.Log("[UMP] Showing privacy options form.");
// PrivacyOptionsForm 무조건 팝업으로 변경[blueasa / 2023-12-14]
ConsentForm.ShowPrivacyOptionsForm((FormError showError) =>
//ConsentForm.LoadAndShowConsentFormIfRequired((FormError showError) =>
{
if (showError != null)
{
Debug.LogErrorFormat("[UMP][LoadAndShowConsentFormIfRequired] Error showing privacy options form with error: {0}", showError.Message);
}
else
{
// 버튼 상태 갱신(필요하면)
// Enable the privacy settings button.
//if (_privacyButton != null)
//{
// _privacyButton.interactable =
// ConsentInformation.PrivacyOptionsRequirementStatus ==
// PrivacyOptionsRequirementStatus.Required;
//}
}
});
}
void GDPRDebugger()
{
Debug.Log("[UMP] GDPRDebugger()");
///Summary
///Use this for debugging
///
// Define the test device ID for debugging
string testDeviceHashedId = "0B030C0B27FA3A0A7FCF5766D3BBBA1A"; // Replace with your actual test device ID
// Create debug settings for consent testing
var debugSettings = new ConsentDebugSettings
{
TestDeviceHashedIds = new List<string>
{
testDeviceHashedId
}
};
// Set the debug geography for testing in the EEA
debugSettings.DebugGeography = DebugGeography.EEA;
Debug.Log("[UMP] GDPRDebugger Set : DebugGeography.EEA");
// Set tag for under the age of consent.
// Here false means users are not under the age of consent.
ConsentRequestParameters request = new ConsentRequestParameters
{
TagForUnderAgeOfConsent = false,
ConsentDebugSettings = debugSettings,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
#endregion
[참조] https://docs.adxcorp.kr/appendix/ump-user-messaging-platform
[사용자 메시지 플랫폼(UMP) Doc] https://developers.google.com/admob/unity/privacy?hl=ko
[GoogleMobileAds.Ump.Api Doc] https://developers.google.com/admob/unity/reference/namespace/google-mobile-ads/ump/api
[GitHub/Sample] https://github.com/googleads/googleads-mobile-unity
'Unity3D > Ad' 카테고리의 다른 글
[GoogleMoblieAds] GDPR/Ads Personalization 동의 여부 확인 방법 (0) | 2024.02.23 |
---|---|
[펌] GDPR에 대해 알아보자 (Feat 애드몹) (0) | 2024.02.23 |
[Error] Build iOS failed: Undefined symbols for architecture arm64: "_GADURequestInterstitial" (2) | 2021.05.26 |
[링크] Very Simple Ads Monetization & Mediation (0) | 2018.01.08 |
[링크] [Unity3D] Google AdMob 연동하기 (0) | 2018.01.08 |