custom-consent-dialogue-admob-gdpr

Custom Consent Dialogue For Google Admob

In the previous tutorial Implement Consent Dialogue For Google Admob gives you good overview about implement AdMob consent SDK in android app and in this tutorial we learn implementing custom consent dialogue. There are two ways to display consent dialogue and get consent from EU citizen.

1.Display Google Rendered Consent Dialogue.

This consent dialogue (form) is only support if you have selected custom set of providers and providers list must be less then or equal to 12.

2. Display Custom Consent Dialogue.

Custom consent dialogue is required when you have selected full list of ad technology providers (Commonly used set of ad technology providers) and dynamically retrieve the full list of ad technology providers from AdMob.

In this tutorial we are going to learn second option. If you want to learn basics about GDPR and EU consent please refer our previous tutorial Implement Consent Dialogue For Google Admob.

1. Project Overview

In this tutorial we customize the consent form design and display custom consent dialogue to take user consent from EU citizen before displaying the ads.This demo contains single activity with two buttons show ads and reset consent.

2. Create / Setup Project

1. Create a new project in Android Studio from File ⇒ New Project and select Basic Activity from the templates.

2. Open build.gradle of main project and add maven dependency that points to Google repository.

3. Open build.gradle under app directory and add following dependency for Consent SDK and Google AdMob.

NOTE : Make sure that this tutorial is only for without mediation ads integration apps, Google is currently unable to obtain and handle consents for mediation network.

4. Add following code into colors.xml, strings.xml and styles.xml file.

colors.xml

strings.xml

styles.xml

3. Design Custom Consent Dialogue

In previous step we have defined some colors and styles which is used to design custom consent dialogue. Now in next step we are going to design some xml files for custom dialogue design.

5. Create new layout files under layout folder named eu_consent.xml. This layout file is used to display custom consent dialog and get consent from the user at first launch of the application. So add following lines of code into eu_consent.xml.

6. Now in next step create new layout files under layout folder named eu_consent_more.xml. Using this layout files we are going to display all the advertise partners of google admob and from this section user can learn how they are collect and use data. Add following lines of code into eu_consent_more.xml.

7. Now create new layout files under layout folder named row_ad_provider.xml. This is the row file which holds list of advertise provider. Add following lines of code into row_ad_provider.xml.

4. Create Adapter And Dialogue

Now design part of consent dialogue is finished let’s create the adapter for advertise providers and consent dialogue helper class.

8.Now create the new class named AdProviders.java under your projects. This class is adapter class which holds list of ad providers and display into consent dialogue. Add following code into AdProviders.java.

9. Create class named ConsentDialogueConstant.java under your projects and add following code which contains constant strings and privacy url to display in dialogue.

10. Now finally create new class named CustomGdprHelper.java file under your project and add bellow lines of code in the file. This is the main helper class which contains all the stuff related to display custom dialog and get consent from the user at first launch of the app.

5. Setup Main Activity

Now all the stuff related to custom consent dialogue is done the final step is to setup main activity and display the consent dialogue from the main activity. For the testing we have added two buttons for reset consent and show interstitial ads inside the main activity.

11. First open activity_main.xml from the layouts and add following lines of code into file. This layout contains two buttons for reset consent and showing interstitial ads from AdMob.

 

12. Finally open your MainActivity.java file and add following line of code inside the the file.

Using above codes of you can call and display custom consent dialogue and reset conset using RESET button  if you want to test again. So all steps are done now run this demo project on real device and check newly designed consent dialogue. This dialogue will display all the ad partners and it’s privacy policy before take the consent from the user.

I hope you like this article. If you have followed this tutorial carefully then application run without any issue. Write us if there is any issue to implement custom consent dialogue or refer our previous tutorial if you learn what is GDPR and how to implement Google rendered Consent Dialogue .

 

Happy Coding 🙂