UMP SDK implementation

623 views
Skip to first unread message

Mirawo

unread,
Jun 5, 2023, 3:46:20 PM6/5/23
to Google Mobile Ads SDK Developers
I am implementing UMP sdk in my app and it is working apparently, but I want to ensure that this is the correct way of implementing it:

Here is my code:

    public class MainActivity extends AppCompatActivity {
      private ConsentInformation consentInformation;
      private ConsentForm consentForm;
   
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
   
        consent();
       }
   
        public void consent() {
            ConsentRequestParameters params = new ConsentRequestParameters
                    .Builder()
                    .setTagForUnderAgeOfConsent(false)
                    .build();
   
            consentInformation = UserMessagingPlatform.getConsentInformation(this);
            consentInformation.requestConsentInfoUpdate(this,
                    params,
                    new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
                        @Override
                        public void onConsentInfoUpdateSuccess() {
                            // The consent information state was updated.
                            // You are now ready to check if a form is available.
                            if (consentInformation.isConsentFormAvailable()) {
                                loadForm();
                            }
                        }
                    },
                    new ConsentInformation.OnConsentInfoUpdateFailureListener() {
                        @Override
                        public void onConsentInfoUpdateFailure(FormError formError) {
                            // Handle the error.
                        }
                    });
   
        }
   
        public void loadForm() {
            // Loads a consent form. Must be called on the main thread.
            UserMessagingPlatform.loadConsentForm(
                    this,
                    new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
                        @Override
                        public void onConsentFormLoadSuccess(ConsentForm consentForm) {
                            MainActivity.this.consentForm = consentForm;
                            if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED) {
                                consentForm.show(
                                        MainActivity.this,
                                        new ConsentForm.OnConsentFormDismissedListener() {
                                            @Override
                                            public void onConsentFormDismissed(FormError formError) {
                                                if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
                                              MobileAds.initialize(this, initializationStatus -> {
            });
                                                }
   
                                                // Handle dismissal by reloading form.
                                                loadForm();
                                            }
                                        });
                            }
                        }
                    },
                    new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
                        @Override
                        public void onConsentFormLoadFailure(FormError formError) {
                            loadForm();
                        }
                    }
            );
        }


I have three questions:

1- Is my implementation looking good?

2- Is it a good way to MobileAds.initialize() when ConsentStatus is ConsentStatus.OBTAINED as I have done?

3- I don't have to do anything more, right? I mean when the user accepts or declines the Form, google will automatically personalize ads without my need of managing that, right? I mean, I don't have to code the personalization part, right?

Mobile Ads SDK Forum Advisor

unread,
Jun 8, 2023, 12:18:43 PM6/8/23
to civic...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for reaching out to us.

With regard to your concern, your implementation looks correct, as long as you've followed the guide from our documentation (https://developers.google.com/admob/android/privacy). For MobileAds.initialize(), just kindly make sure that you have your app initialize the Google Mobile Ads SDK before loading the ads.

If you configure everything using the UMP, then the UMP SDK gets this information based on the availability of a form, use the isConsentFormAvailable() (https://developers.google.com/admob/ump/android/api/reference/com/google/android/ump/ConsentInformation#public-abstract-boolean-isconsentformavailable) method on the ConsentInformation instance you created. This occurs on app launch: you should request an update of the user's consent information at every app launch, using requestConsentInfoUpdateWithParameters:completionHandler: (https://developers.google.com/admob/ios/privacy/api/reference/Classes/UMPConsentInformation#-requestconsentinfoupdatewithparameters:completionhandler:) before loading a form. This can determine whether or not your user needs to provide consent if they hadn't done so already or if their consent has expired. 

This message is in relation to case "ref:_00D1U1174p._5004Q2m9dSV:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team

 



Mirawo

unread,
Jun 8, 2023, 1:32:55 PM6/8/23
to Google Mobile Ads SDK Developers
Okay, but as you can see in my implementation, Mobile Ads are only initialized when the user accepts or declines the consent of the form (When ConsentStatus is OBTAINED). Okay so is that okay? I mean in that case if the user do not accept or decline the form, some ads could be loaded before MobileAds are initialized, but that is okay as in that case I do not want any ad to be shown as the user has not given any consent, right? I mean, I did that so that if no consent is given, although some ads could be loaded, as Mobile Ads is not initialized, no ads will be shown. Is that Okay?

Mobile Ads SDK Forum Advisor

unread,
Jun 14, 2023, 2:14:47 AM6/14/23
to civic...@gmail.com, google-adm...@googlegroups.com
Hello Mirawo,

With regards to your concern, yes, your current implementation is acceptable. There are no issues with your implementation as long as the ads do not violate any of our policies: https://support.google.com/admob/answer/6128543?hl=en

Feel free to reach back to us if any further issues or concerns.
Reply all
Reply to author
Forward
0 new messages