B4A Class AdMobConsentFormMultilang

Hi

This class shows the consent form required for ads in EEC countries and UK in several languages (see Consts in Class_Globals). It's almost a clone of the Google Consent form.

Code is B4X, written for B4A. For the moment I don't use B4J or B4I, but I guess it's not much effort to adapt this class for the three plattforms. Perhaps some work with B4XCanvas or stringUtils.MeasureMultilineTextHeight...

Translations are taken (tedious work) from the HTML files contained in the attached consentform.zip file, obtained from this page. Will someone ? ever run into direct form creation based on these HTML files? I've tried by WebView, and almost got it, but had no luck on catching the clicked button on the opened HTML, and that's why I created this class.
As each developer may choose his ads providers, each developer has to download his own file "ad_technology_provider_privacy_urls.csv" from his AdMob console AdMob providers download location.PNG. This information is provided by AdMob in ConsentManager (FirebaseAdMob library) through consent.RequestInfoUpdate, but I haven't found the way to extract it from there.

Class module is included in the example attached file.

I know that there will not be many Chinese, Japanese or Korean here in Europe who install the application but, who knows...? :)

Please, feel free to change, improve and/or distribute free of charge
 

Attachments

  • consentform.zip
    71.7 KB · Views: 311
  • AdMobConsentFormMultilang.zip
    35.6 KB · Views: 342

Jack Cole

Well-Known Member
Licensed User
Longtime User
Thanks for doing this work. I have attached an example project of how to do this with the html pages. Please feel free to integrate it into your class. I use the webview event _OverrideUrl to catch the user clicks.
 

Attachments

  • b4xconsent.zip
    84.2 KB · Views: 310

Ivan Aldaz

Member
Licensed User
Longtime User
Thank you, Jack.

First step done. Now the second part of the problem is to catch the click on the text links "Learn how App Name and our partners collect and use your data" and "How App Name uses your data". I've tried with the event WebView1_PageFinished, but always get "file:///#" as URL.

In addition, it would be necessary to include the list of providers and their privacy policy URLs, because we have to facilitate access to the privacy policy of each of them.

And the last drawback is that we have to modify each HTML to include the link to our privacy policy ("How App Name uses your data"), and the name and icon of our app. I have tried to edit the variables in these blocks of the HTML but again with no luck:

B4X:
     // Set app name.
      var appName = formInfo['app_name'] || '';
      if (appName.length <= 0) {
        formLoadCompleted('Error: invalid app name.');
      }
      var appNameEls = document.getElementsByClassName('app_name');
      for (var i = 0; i < appNameEls.length; i++) {
        appNameEls[i].innerText = appName;
      }

      // Add the app icon.
      var appIconSrc = formInfo['app_icon'] || '';
      if (appIconSrc) {
        var appIconEl = document.createElement('img');
        appIconEl.src = appIconSrc;
        appIconEl.id = 'app_icon';
        appIconEl.className = 'app_icon';
        obj.titleAppNameEl.parentNode.insertBefore(appIconEl, obj.titleAppNameEl);
      }

     // Create the app's privacy policy URL handler.
      var app_privacy_url = formInfo['app_privacy_url'];
      if (!app_privacy_url) {
        formLoadCompleted('Error: must provided app privacy URL.');
        return;
      }

I'm not familiar at all with HTML or Java, but seems that there is an additional JSON file that contains or references these variables. Even having that file available, I couldn't include or link it to the HTML.
 
Last edited:

Jack Cole

Well-Known Member
Licensed User
Longtime User
Ok, I think I got everything working in this example. It uses javascript to set the app name and to set a function for the privacy policy URL click. You can set the app name and privacy policy URL in the global variables of ConsentPage.
 

Attachments

  • b4xconsent.zip
    85 KB · Views: 293

Ivan Aldaz

Member
Licensed User
Longtime User
Hi again, Jack.

This is the sequence that I see:

When button1 is clicked "ConsentPage" is loaded. At the end of the 'B4XPage_Created' event the line
B4X:
B4xConsent.Initialize(Me, Root, Lang, jsonString)
is executed, and the flow goes to the 'Initialize' Sub in 'B4X_Ad_Consent' module. When 'htmlcode' is loaded in WebView1 ...
B4X:
Webview1.LoadHtml(htmlcode)
... the event 'WebView1_PageFinished' is raised. In this Sub we have
B4X:
wve.executeJavascript(Webview1, $"setUpConsentDialog(${SettingsJSON});showAppPrivacyPolicy = dismissConsentModal('show_privacy_policy');"$)
, that produces the 'Webview1_OverrideUrl' event, in which the line
B4X:
  ParentModule.Consent_Response(Url)
, leads the flow to the Sub Consent_Response module in 'ConsentPage', with the string 'show_privacy_policy', that makes the Privacy Policy to appear.

Summarizing: when the button is clicked for the first time the app privacy policy page is open, but we only want to show it when the corresponding link is clicked (this works fine). This only happens the first time the button is clicked, and I think it's just a matter of sorting things, or modify the code a bit

Note that the result is the same when clicking the app privacy policy link and the one for showing providers list (the one above the button for personalized ads). The app privacy policy is shown in both cases.

And still we need to load the list of ads providers (when the link works), and create links/buttons to their privacy policies automatically. It would be better, of course, if it is obtained from ConsentManager, but I don't know if coding this is worth it. Can be done as in my example, downloading our own CSV file from AdMob Console and showing the list when the now-not-working link works.

Thank you
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
Summarizing: when the button is clicked for the first time the app privacy policy page is open, but we only want to show it when the corresponding link is clicked (this works fine). This only happens the first time the button is clicked, and I think it's just a matter of sorting things, or modify the code a bi

Change the code in the Webview1_PageFinished sub to:

B4X:
wve.executeJavascript(Webview1, $"setUpConsentDialog(${SettingsJSON});showAppPrivacyPolicy = function() {dismissConsentModal('show_privacy_policy');}"$)

I will look into the choices of ad providers.
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
I think probably the best way to do it is to load your page to show the providers. I modified the code to make it where you can do that when they click on the link on the first page.
 

Attachments

  • b4xconsent.zip
    85.1 KB · Views: 277

Ivan Aldaz

Member
Licensed User
Longtime User
Hi

I've added my page for ad providers, and modified a bit the code to show the app policy from the link on the first page. Instead of doing it through an intent, the page is opened in a WebView with a 'Back' button that closes the page and returns to the app. I think it's more agile this way to go back and forth, especially if you are going to see several policies.

The only thing I'm missing now is the app icon. It can be shown in the ad providers panel, but not in the other two panels yet. I think it is not important at all, because these screens are normally displayed only once, when the application is first run.

Thanks for your work, Jack
 

Attachments

  • b4xconsent.zip
    94.9 KB · Views: 294

Jack Cole

Well-Known Member
Licensed User
Longtime User
I added support for the icon. There was also an issue with the back button event in ConsentPage for the privacy policy. It was typed as btnBackWebView_Click. Should have not included the View part. I think it is in pretty good shape now.
 

Attachments

  • b4xconsent.zip
    106.8 KB · Views: 270

Ivan Aldaz

Member
Licensed User
Longtime User
I see there is only one thing missing. In old versions of Android, the icon path "file:///android_asset/icon.png" is not valid. Adding this Erel's snippet to the code we get a string like "file:///data/user/0/b4a.example/files/virtual_assets/icon.png.unpacked" for old versions, and then it works fine in both old and new versions of Android
 

Attachments

  • b4xconsent.zip
    106.9 KB · Views: 253
Top