Android Tutorial FirebaseAdMob and User Consent

Discussion in 'Tutorials & Examples' started by Erel, May 23, 2018.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    More information: https://developers.google.com/admob/android/eu-consent
    By default, AdMob serves personalized ads.
    With the new GDPR law, publishers (you) need to request consent before the private data can be used to serve personalized ads to EU users.

    The main steps are:

    1. Check the current consent state, usually in the starter service.
    2. If the consent state is unknown and the user is from the EU (or his location is unknown) then show the consent form.

    [​IMG]

    This step must be done from an Activity.

    3. Show non-personalized or personalized ads based on the consent state and location.

    The limit on 12 providers was removed. Make sure to use FirebaseAdMob v1.55+.

    Note that the Google consent form will only work if there are 12 or less ad technology providers. There are 200 by default so you need to change it in your AdMob console:
    Blocking Controls - EU USER CONSENT tab:


    [​IMG]


    Testing

    In order to test the behavior you can can add your device as a test device and set whether the location should be treated as coming from the EU:
    Code:
    consent.AddTestDevice("D4AC977CA12D122C4563730CC762C302"'check the unfiltered logs for the device id after calling RequestInfoUpdate
    consent.SetDebugGeography(True'True = EU, False = Non-EU
    You can set the consent state yourself and it will be saved automatically by setting the ConsentState property. This can be useful for debugging and to allow the user to change the previously selected option.

    Starter service code:

    Code:
    Sub Service_Create
       consent.Initialize(
    "consent")
       consent.AddTestDevice(
    "D4AC977CA12D122C4563730CC762C302")
       consent.SetDebugGeography(
    True'comment for regular operation
       consent.RequestInfoUpdate(Array("pub-144444444"))
       
    Wait For consent_InfoUpdated (Success As Boolean)
       
    If Success = False Then
           
    Log($"Error getting consent state: ${LastException}"$)
       
    End If
       
    Log($"Consent state: ${consent.ConsentState}"$)
       
    Log("EU: " & consent.IsRequestLocationInEeaOrUnknown)
       
    Do While IsPaused(Main)
           Sleep(
    100)
       
    Loop
       CallSubDelayed(Main, 
    "ConsentStateAvailable")
    End Sub
    Main activity code:

    Code:
    'show the consent form if needed
    Sub ConsentStateAvailable
       
    Dim consent As ConsentManager = Starter.consent
       
    If consent.ConsentState = consent.STATE_UNKNOWN And consent.IsRequestLocationInEeaOrUnknown Then
           
    'Set last parameter to False if you don't want to show the "pay for ad-free" option.
           'Change privacy policy URL.
           consent.ShowConsentForm("https://www.mysite.com/privacy.html"TrueTrueTrue)
           
    Wait For Consent_FormResult (Success As Boolean, UserPrefersAdFreeOption As Boolean)
           
    If Success Then
               
    Log($"Consent form result: ${consent.ConsentState}, AdFree: ${UserPrefersAdFreeOption}"$)
           
    Else
               
    Log($"Error: ${LastException}"$)
           
    End If
       
    End If
       LoadAd
    End Sub

    'load ads:
    Sub LoadAd
       
    Dim builder As AdRequestBuilder
       builder.Initialize
       
    Dim consent As ConsentManager = Starter.consent
       
    If consent.IsRequestLocationInEeaOrUnknown Then
           
    If consent.ConsentState = consent.STATE_NON_PERSONALIZED Then
               builder.NonPersonalizedAds
           
    Else if consent.ConsentState = consent.STATE_UNKNOWN Then
               
    Return
           
    End If
       
    End If
       builder.AddTestDevice(
    "D4AC977CA12D122C4563730CC762C302")
       adview1.LoadAdWithBuilder(builder)
    End Sub
    Ad free option

    If the user selects this option then the ConsentState will be kept UNKNOWN and UserPrefersAdFreeOption will be true (nothing else happens).


    Dependencies: FirebaseAdmob v1.50+ (https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.59340/#post-590564)
     
    Last edited: Mar 31, 2019
    Ohanian, fredo, Pendrush and 5 others like this.
  2. Multiverse app

    Multiverse app Active Member Licensed User

    Will failing this before Friday can get the AdMob account/app banned?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Do you mean to ask whether you can implement it right now or wait for 25 May?

    I don't think that you will get banned. Based on my tests no ads are returned for non-personalized requests.
     
    Multiverse app likes this.
  4. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    So how are we supposed to know which ad technology providers to choose? I can't find anything in my AdMob console that tells me which ones I am currently using - so if I just take a stab at it, I will most likely end up impacting my EU revenue (actually, if I am currently using say 100 & I have to choose only 12, then I guess that will happen anyway).

    I think that no matter what we do, there will be a big hit on EU ad revenues - lucky for me it's "only" about 10% of my total revenue...

    - Colin.
     
  5. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    OK - on further investigation, I have found that if you go into the Ad Review Center in your AdMob console you can filter the list of ads by Ad Network. I guess you could use this to see how many ads are being shown from each ad technology provider, but there are 2 issues with this:

    1) You can only apply 1 Ad Network filter at a time - so you'll have to go through them 1 by 1; and
    2) You can't also filter by country/region - which means you still don't know if those ads are actually being shown in EU.

    - Colin.
     
  6. kisoft

    kisoft Active Member Licensed User

    HI
    I understand that if the user does not agree to the display of advertisements, the ad will not be displayed. How to block an application in the absence of such consent.
     
  7. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    My understanding is that every time the app starts you check the current consent state & if there is no consent, you present them with the dialog with 3 options:

    1) Consent to personalized ads; or
    2) Consent to non-personalized ads; or
    3) Pay for an ad-free version (which can either be sending them to Play Store to download a paid version, or via an in-app purchase).

    If they don't pick one of those options, then you have 3 choices:

    1) Let them use the app with no ads; or
    2) Let them use the app & where you would have shown an ad, instead show a "pay for the app you cheap bastard" message; or
    3) Exit the app.

    I think I will probably implement choice 3 - so if they don't consent to any form of ads & don't want to pay for the app, then they won't be able to use it.

    - Colin.
     
  8. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    I've been trying to test this today, however even when I set consent.SetDebugGeography(True), it still returns EU: false in the logs. The device id I'm using is the one that comes up when you first connect to a device:

    Or is this not the correct one? I can't find another device id in the unfiltered logs, so I'm hoping this is the correct one!

    - Colin.
     
  9. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    Shouldn't this be the advertising id? According to the Google doco:
    Even so, I couldn't find the advertising id in the unfiltered logs of my test device, but I was able to find it in the Google Settings app on the device. Unfortunately, even using that id, I still can't get consent.SetDebugGeography(True) to work.

    - Colin.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    No. It is a device id. I see it here in the unfiltered logs. It is the same id that you use to request test ads.

    The user is not asked to agree for ads, only to agree to personalized ads. See the code in LoadAd. If the user is from the EU and hasn't gave consent to personalization then you show him non-personalized ads.
     
    Last edited: May 27, 2018
  11. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    Hmmm - I don't use a device id to get test ads. I just use the test ad unit ids - https://developers.google.com/admob/android/test-ads. I tried using the device id from the log (& using the GetDeviceId per Android Device Unique ID - Alternative to PhoneId) however it wouldn't set the location as EU.

    From the fairly large amount of reading I've done on this over the past couple of weeks, I'm pretty sure that you still have to get consent for non-personalized ads too. This is from the AdMob EU User Consent Policy (https://support.google.com/admob/answer/7666366)

    I guess this is why their dialog has options for the user to give consent for personalized or non personalized ads. By tapping on the non personalized option, they are giving consent.

    - Colin.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    This has nothing to do with the device id you need. It works here with the device id from the logs.

    You should read the terms and follow them as you or your lawyer understand them.
    I'm not a lawyer. As I understand it, the quote you posted is not relevant for mobile apps as you are not storing cookies. It is relevant for web sites and it means that web sites should show the "accept cookies" message.
     
  13. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    The device id in the logs is the same as the device id returned by that function - & it doesn't work. I have copied the entire unfiltered log to Notepad++ & searched for a device id & found nothing.

    - Colin.
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    When you call consent.RequestInfoUpdate it must print in the unfiltered logs:

    Use ConsentInformation.getInstance(context).addTestDevice("D4AC977CA12D122C4563730CC762C302") to get test ads on this device.

    Or:

    This request is sent from a test device.

    If you don't see it then maybe you are unable to see the unfiltered logs. Make sure to use B4A v8+ with the latest version of B4A-Bridge. If not working then switch to USB debug mode.
     
  15. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    Thank you for providing that crucial piece of information Erel. I can sense your frustration with me seemingly not understanding where this device id was coming from, however I am equally frustrated because I've spent pretty much all day trying to make it work & the final piece of the puzzle ("When you call consent.RequestInfoUpdate it must print in the unfiltered logs:") is nowhere to be found in the tutorial. :)

    Yes, the comment about looking in the unfiltered logs (which I was doing) is there - however it doesn't say that the device id will be printed after you call consent.RequestInfoUpdate. All it says is "'check the unfiltered logs for the device id". Perhaps I'm just dumber than the average developer... :)

    - Colin.
     
  16. kisoft

    kisoft Active Member Licensed User

    I've pasted the code but I can not compile. I'm getting a syntax error: unknown user ConsentState.
    I've updated the FirebaseAdmob v1.50 library. I have b4a V8.0
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the exact error message from the compilation window?

    Check the library version in the libraries tab. If it is not 1.50 then you haven't copied the library to the correct place.
     
  18. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    Make sure you either copied the v1.50 of the FirebaseAdmob library to the Libraries directory, or if you put it in the Additional Libraries directory, you deleted the older one our of the Libraries directory. I made that mistake when I copied it to my Additional Libraries directory. Can't remember if I got that error though...

    - Colin.
     
  19. kisoft

    kisoft Active Member Licensed User

    The library is visible as 1.50 and is in the directory C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries

    I'm getting a syntax error:
    unknown user: ConsentState
    Expected non code block
    unknown user: ShowConsentForm
    unknown user: ConsentState
    unknown user: Consent
    unregistered "CONSENT" variable it is used before assigning any value
    unregistered "CONSENT" variable it is used before assigning any value
    unregistered "CONSENT" variable it is used before assigning any value
     
  20. tufanv

    tufanv Expert Licensed User

    I am still not sure , if we have to implement this or not . Is there a specific google announcement that this HAS TO BE DONE ?
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice