Ghostw4lk
Ghostw4lk

Reputation: 127

How to integrate "Tracking Transparency" and "EU Consent" in Google Admob in Swift/iOS?

I'm trying to implement Admob with "Tracking Transparency" and "EU Consent" in Swift.

My app is for iOS 14.0+ devices, so I've followed the instructions on https://developers.google.com/admob/ios/ios14. To be compliant with EU consent for GDPR, I implemented the instructions from https://developers.google.com/admob/ump/ios/quick-start (This is the current implementation for EU consent, not the legacy implementation.).

After that, the dialog "To track users across devices" is shown after the first start of the app. After this, the EU consent dialog will be shown. All works fine.

My question is, is my implementation working so that when Google initializes Admob, it will respect the preferences of the user with tracking transparency and EU consent settings?

Here is my Code:

import SwiftUI
import GoogleMobileAds
import AppTrackingTransparency
import UserMessagingPlatform

@main
struct SampleAdmobWithEuConsent: App {
    
    init() {
        requestIDFA()
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
    
    private func initGoogleMobileAds() {
        GADMobileAds.sharedInstance()
            .start(completionHandler: nil)
    }
    
    private func requestIDFA() {
        ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
            // Tracking authorization completed. Start loading ads here.
            showConsentInformation()
        })
    }
    
    private func showConsentInformation() {
        let parameters = UMPRequestParameters()
        
        // false means users are not under age.
        parameters.tagForUnderAgeOfConsent = false
        
        UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
            with: parameters,
            completionHandler: { error in
                if error != nil {
                    // Handle the error.
                } else {
                    // The consent information state was updated.
                    // You are now ready to check if a form is
                    // available.
                    loadForm()
                }
            })
        
    }
    
    func loadForm() {
        UMPConsentForm.load(
            completionHandler: { form, loadError in
                if loadError != nil {
                    // Handle the error
                } else {
                    // Present the form
                    if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required {
                        form?.present(from: UIApplication.shared.windows.first!.rootViewController! as UIViewController, completionHandler: { dimissError in
                            if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.obtained {
                                // App can start requesting ads.
                                initGoogleMobileAds()
                            }
                        })
                    }
                }
            })
    }
}

I couldn't find a method in GADMobileAds.sharedInstance() to set specified settings, based on the user's preferences from the dialogs. (E.g.: Track me across apps or show me personalized ads).

Thanks in advance!

Upvotes: 3

Views: 3408

Answers (1)

El_Loco
El_Loco

Reputation: 1866

I followed your code example and when I test on my simulator, I never get the EU consent dialog. Although I select allow tracking in the first dialog.

Similar Question

Upvotes: 0

Related Questions