Android Question Problem: GDPR consent showing for all IPs – how to restrict to EU only?

Hi everyone,
I’m using the AdsHelper class to display the GDPR consent form. However, I have a problem: the form is being shown for all IPs.
I want the form to be displayed only when the user is coming from European IPs.
What should I do to implement this condition?

I disabled this line of code, but it still shows up for all IPs.

B4X:
m.SetConfiguration(m.CreateRequestConfigurationBuilder(Array("8A2BC683096DA70A5AB35C9F69DA8B52")))
Ads.ResetConsentStatus

Public Sub SetConsentDebugParameters (TestId As String, InEEA As Boolean)
    Log("Consent debug parameters are being set. Don't forget to remove before production.")
    ConsentDebugSettings.InitializeNewInstance("com.google.android.ump.ConsentDebugSettings$Builder", Array(ctxt))
    Dim geo As Int
    If InEEA Then geo = 1 Else geo = 2
    ConsentDebugSettings.RunMethod("setDebugGeography", Array(geo))
    ConsentDebugSettings.RunMethod("addTestDeviceHashedId", Array(TestId))
    ConsentDebugSettings = ConsentDebugSettings.RunMethod("build", Null)
End Sub

If ConsentDebugSettings.IsInitialized Then
           ConsentRequestParameters.RunMethod("setConsentDebugSettings", Array(ConsentDebugSettings))
End If
 

zed

Well-Known Member
Licensed User
To ensure the GDPR consent form only appears for users located in the EEA, you must disable debugging settings and allow the Google UMP SDK to automatically detect IP geolocation.
The code you shared uses ConsentDebugSettings, which forces the SDK to simulate geolocation within the EEA (European Economic Area) or outside the EEA, depending on the value of InEEA. This bypasses actual IP detection.

geo = 1 - forces geolocation within the EEA
geo = 2 - forces geolocation outside the EEA

Even if you disable a line, if ConsentDebugSettings is initialized and applied to ConsentRequestParameters, the SDK behaves as if the user were in the EEA.
To display the form only for European IP addresses, you must:

Remove or completely comment out the SetConsentDebugParameters block in production.

' Do not call this method in production
' SetConsentDebugParameters(TestId, True)

Do not include ConsentDebugSettings in ConsentRequestParameters.

If ConsentDebugSettings.IsInitialized Then
' Remove this line in production
' ConsentRequestParameters.RunMethod("setConsentDebugSettings", Array(ConsentDebugSettings))
End If

Let the Google UMP SDK automatically handle IP geolocation: The SDK uses the user's IP address to determine if they are in the EEA. If so, the form will be displayed automatically.
 
Upvote 0
Top