How to Test User Consent Status (GoogleMobileAds UMP SDK)

1k views Asked by At

I'm in the process of integrating the GoogleMobileAds & User Messenger Platform SDK for iOS.

I understand it offers a way for users to consent or not consent inside the EEA.

Firstly you test to see if consent is required:

UMPFormStatus formStatus = UMPConsentInformation.sharedInstance
                                 .formStatus;
                         if (formStatus == UMPFormStatusAvailable) {
                           [self loadForm];
                         }
...

The Admob guide says you can serve non-personalised ads as follows:

GADRequest *request = [GADRequest request];
GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{@"npa": @"1"};  //this being the key line
[request registerAdNetworkExtras:extras];

If the user consents, ads can be loaded fine, as GoogleMobileAds default is to serve personalised ads...

However, if a user does choose not to consent, how do we programmatically test the consent status before loading Ads? Or does the GoogleMobileAds monitor this inside Admob and only serve non-personalised ads based on the users input?

I haven't found an answer to this on Stack or Github etc. Thank you for your time.

Edit: I have since discovered that if a user doesn't consent, no ads are shown... But a test to check consent would still be helpful, as you could manually load non-personalised ads (npa)... But I can't find how to test the consent, so the question above, still stands. Thank you.

1

There are 1 answers

0
John Doe On

After GDPR consent has been collected, you can read consent choices from local storage following the TCF v2 spec. The IABTCF_PurposeConsents key indicates consent for each of the TCF purposes.

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
// Example value: "1111111111"
String purposeConsents = sharedPref.getString("IABTCF_PurposeConsents", "");
// Purposes are zero-indexed. Index 0 contains information about Purpose 1.
if (!purposeConsents.isEmpty()) {
  String purposeOneString = purposeConsents.charAt(0);
  boolean hasConsentForPurposeOne = purposeOneString.equals("1");
}

See https://developers.google.com/admob/android/privacy/gdpr#how_to_read_consent_choices