왜?
2024년 1월 16일 이후부터는 유럽 사용자에게 광고를 표시하기 위한 EEA 요구 사항 때문에 앱에 GDPR 동의 메시지를 추가해야 합니다.
이를 하지 않으면 광고 수익에 큰 영향을 받게 됩니다.
어떻게?
Google AdMob의 공식 영상을 보면 구현 방법을 배울 수 있습니다.
하지만 언제나 그렇듯이, Google 문서는 UIKit 방식만 보여줄 뿐 SwiftUI 방식은 보여주지 않습니다.
SwiftUI 예제
하루 동안 탐구한 끝에, 마침내 순수 SwiftUI로 작동하게 만들었습니다.
사실 꽤 간단합니다:
import SwiftUIimport UserMessagingPlatform
struct ContentView: View { @AppStorage("gdprConsentShown") var gdprConsentShown = false
var body: some View { VStack { } .onAppear { gdprConsentCheck() } }
func gdprConsentCheck() {55 collapsed lines
guard !gdprConsentShown else { return }
// Create a UMPRequestParameters object. let parameters = UMPRequestParameters() let debugSettings = UMPDebugSettings () // - This is for mimicking EEA users when you're outside the EU. // - Use a simulator so you can read the consent form. debugSettings.geography = .EEA parameters.debugSettings = debugSettings
// Set tag for under age of consent. false means users are not under the age of consent. If you turn this on, no consent form is presented. parameters.tagForUnderAgeOfConsent = false
// Request an update for the consent information. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) { (requestConsentError) in if let consentError = requestConsentError { // Consent gathering failed. return print("Error: \(consentError.localizedDescription)") } // Load and present the consent form. loadAndPresentConsentForm() } }
func loadAndPresentConsentForm() { UMPConsentForm.load { (form, loadError) in if let error = loadError { // Consent form could not be loaded. return print("Error: \(error.localizedDescription)") }
if let form = form { if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene { if let window = windowScene.windows.first { if let rootViewController = window.rootViewController { form.present(from: rootViewController) { (dismissError) in if let error = dismissError { // Consent form could not be dismissed. print("Error: \(error.localizedDescription)") gdprConsentShown = false } else { // Consent form was dismissed. // Check the consent status. let status = UMPConsentInformation.sharedInstance.consentStatus print("Consent status: \(status)") gdprConsentShown = true } } } } } } } }}네, if let이 절반쯤 ChatGPT로 만든 거라 못생겼지만, 요점은 이해하실 겁니다. 저는 이를 수정해서 모든 것을 다른 뷰에 넣었습니다.
그래서 제가 만드는 모든 앱에서 그 뷰를 복사해서 붙여넣기만 합니다. 제 메인 뷰에서 사용하는 방법은 다음과 같습니다:
//for ads and consent form @State var readyToShow = false @State private var bannerView: BannerView? = nil ///// context .onAppear() { // create the banner onAppear, readyToShow is false by default bannerView = BannerView(readyToShow: $readyToShow, adUnitID: "ca-app-pub-yourKeyHere") // This performs the consent form logic inside the bannerView, if everything goes well, toggle readyToShow to true. bannerView?.gdprConsentCheck() } .toolbar { ToolbarItem(placement: .bottomBar) { // So only users who passed the consent form will see this banner ad. if !adRemoved && readyToShow{6 collapsed lines
bannerView .frame(width: GADAdSizeBanner.size.width, height: GADAdSizeBanner.size.height) }
} }맞춤형 광고
맞춤형 광고를 표시할지 여부를 제어하기 위해, 예전에는 광고 요청 옵션을 다음과 같이 설정했습니다:
import GoogleMobileAds
let request = GADRequest()let extras = GADExtras()extras.additionalParameters = ["npa": "1"] // This means no personalized ads are shownrequest.register(extras)기억하세요, App Store 규정 준수를 위해 ATT를 설정해야 합니다.
하지만 이제는 Google AdMob과 상호작용하는 것이 아무 소용이 없습니다. UserMessagingPlatform을 사용하면 Google이 자사 플랫폼에서 “개인화”를 관리하기 때문입니다.
“혹시 아직도 누군가에게 도움이 될까 해서 확인차 말씀드리면, Android에서 UMP SDK를 사용하면 npa=1을 설정할 필요가 없습니다. UMP SDK는 TCF 문자열을 shared preferences에 기록하며(관련 정보: https://support.google.com/admob/answer/9760862), Google Mobile Ads SDK는 광고 요청 시 TCF 문자열을 읽습니다.” - Eric, Mobile Ads SDK 팀 - 더 보기
이것이 제가 Google AdMob 포럼에서 읽은 내용입니다.
Android용이라고 했지만, iOS에서도 같은 방식으로 작동한다고 생각합니다.
그래도 어차피 Apple을 위해 ATT를 구현해야 하므로, 지금은 유지하고 있습니다.
이 가이드가 상황을 조금이나마 단순하게 만들고 도움이 되었으면 합니다.