iOS Tutorial iAdMob and User Consent

Discussion in 'iOS Tutorials' started by Erel, May 24, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    More information: https://developers.google.com/admob/ios/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 when the app starts.
    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]

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

    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.LogDeviceIdForDebugging
    consent.AddTestDevice(
    "927915D1-CAE8-4F99-B04C-57345B7DECF4")
    consent.SetDebugGeography(
    True'comment for regular operation (True = from 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.

    Code:
    Code:
    'Application_Start
    consent.Initialize("consent")
    consent.LogDeviceIdForDebugging
    consent.AddTestDevice(
    "927915D1-CAE8-4F99-B04C-57345B7DECF4")
    consent.SetDebugGeography(
    True'comment for regular operation
    consent.RequestInfoUpdate(Array("pub-133333329340"))
    Wait For consent_InfoUpdated (Success As Boolean)
    If Success = False Then
       
    Log($"Error getting consent state: ${LastException}"$)
    End If
    Log($"Consent state: ${consent.ConsentState}"$'0 - UNKNOWN, 1 - NON_PERSONALIZED, 2 - PERSONALIZED
    Log(consent.IsRequestLocationInEeaOrUnknown)
    ConsentStateAvailable
    '**********************

    Sub ConsentStateAvailable
       
    If consent.ConsentState = consent.STATE_UNKNOWN And consent.IsRequestLocationInEeaOrUnknown Then
           consent.ShowConsentForm(Page1, 
    "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


    Sub LoadAd
       
    Dim builder As AdRequestBuilder
       builder.Initialize
       
    If consent.IsRequestLocationInEeaOrUnknown And consent.ConsentState <> consent.STATE_PERSONALIZED Then
           builder.NonPersonalizedAds
       
    End If
       builder.AddTestDevice(
    "bb5420c11bebc5700781d810ca2bc2d0"'this is a different id than the above. Check the logs for the correct id.
       ad.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).

    Bundle

    Unzip the attached zip and copy PersonalizedAdConsent.bundle to <project>Files\Special:

    [​IMG]

    Depends on iAdMob v1.6+ (https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.48179/#post-590795)
     

    Attached Files:

    JordiCP, MarcoRome and Pendrush like this.
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