I switched from the deprecated GDPR Consent Library to the new User Messaging Platform, and used the code as stated in the documentation.
I noticed that when the user clicks on Manage Options then Confirm choices, ads will stop displaying altogether (Ad failed to load, no ad config), and I can't find anyway to check if the user didn't consent to the use of personal data.
This is problematic as my app relies purely on ads, and I will be losing money if ads don't show up, so I want to make it mandatory for users to consent to the use of their personal data, otherwise the app should be unusable.
I have made a test project on Github so everyone can test this behavior. If you are not using an emulator, then you need to change the "TEST_DEVICE_ID" to yours.
How can I achieve this?
The UMP writes its output to some attributes in
SharedPreferences
, outlined here. You can write some helper methods to query these attributes to find out what level of ad consent the user has given or whether the user is EEA or not, but you will need to look at more than just theVendorConsents
string.There are generally 5 attributes you will want to look for to determine whether ads will be served:
IABTCF_gdprApplies
- An integer (0 or 1) indicating whether the user is in the EEAIABTCF_PurposeConsents
- A string of 0's and 1's up to 10 entries long indicating whether the user provided consent for the 10 different purposesIABTCF_PurposeLegitimateInterests
- A string of 0's and 1's up to 10 entries long indicating whether the app has legitimate interest for the 10 different purposesIABTCF_VendorConsents
- A string of 0s and 1s that is arbitrarily long, indicating whether a given vendor has been given consent for the previously mentioned purposes. Each vendor has an ID indicating their position in the string. For example Google's ID is 755, so if Google has been given consent then the 755th character in this string would be a "1". The full vendor list is available here.IABTCF_VendorLegitimateInterests
- Similar to the vendor consent string, except that it indicates if the vendor has legitimate interest for the previously indicated purposes.Per the Google documentation here there are really only a few practical outcomes from the UMP Funding Choices form with respect to serving ads:
This is a pretty non-ideal set of options, since #3 is extremely unlikely to ever occur and #2 and #4 result in the user getting an ad-free app without paying. For all practical purposes, this has removed the "non-personalized ads" option that was in the legacy consent SDK (and the option to purchase the ad-free app) and replaced it with simply disabling ads entirely.
I've written a few helper methods to at least let you query what the user actually selected and act accordingly.
Note
PreferenceManager.getDefaultSharedPreferences
is not deprecated - you just need to make sure to include the androidx import (import androidx.preference.PreferenceManager
). If you include the wrong one (import android.preference.PreferenceManager
), it will be marked as deprecated.Edit: Example integration
Here is an example implementation of a
ConsentHelper
method for managing calling the UMP SDK and handling the results. This would be called on app load (e.g. in the activityonCreate
) withThis handles waiting to initialize the MobileAds SDK until after obtaining consent, and then uses a callback to begin loading ads after the consent workflow is complete.