What should be put inside onConsentFormDismissed method of UMP SDK?

551 Views Asked by At

I have followed the official Android Doucumentation to implement UMP.

This is the code I have:

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) {
                                                // App can start requesting ads.
                                                 //what should be here?
                                            }

                                            // Handle dismissal by reloading form.
                                            loadForm();
                                        }
                                    });
                        }
                    }
                },
                new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
                    @Override
                    public void onConsentFormLoadFailure(FormError formError) {
                        loadForm();
                    }
                }
        );
    }

Okay, if I have implemented it correctly, my question is, what should I put inside the following if-statement:

 if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
                                                // App can start requesting ads.
                                                 //what should be here?
                                            }

Maybe initializing mobile ads?:

 MobileAds.initialize(this, initializationStatus -> {
});

I don't know what would be the best option. Because maybe if an ad is loaded before the user has accepted or declined the form, trying to load ads without mobile ads initialized would not be a good practice. I appreciate all the possible help :)

1

There are 1 best solutions below

0
On

I highly recommend to load all ads after the user gave his consent. According to the GDPR, you have to obtain consent for collecting personalized user data. AdMob and AdSense collect this personal user data. [Here][1] you can see what google wants you to do. Also the youser must give his consent when you want to share personal data with third parties, especially when you send this information to a country outside of GDPR range.

Also an option: You put a public static boolean consentGiven = false; somewhere in your application. In the if-statement you set it to true (of course after the user clicked on consent). Then you can always check the variable consentGiven before you collect personal information in any way. I know thst this can seem lika a lot effort, but its the laws.