0

I want to understand what should be the behaviour of GDPR consent form when the device is offline. I checked a code for the GDPR consent as below:

package com.example.app;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

import com.google.ads.consent.ConsentForm;
import com.google.ads.consent.ConsentFormListener;
import com.google.ads.consent.ConsentInfoUpdateListener;
import com.google.ads.consent.ConsentInformation;
import com.google.ads.consent.ConsentStatus;

import java.net.MalformedURLException;
import java.net.URL;

public class GdprHelper {

    private static final String PUBLISHER_ID = "YOUR-PUBLISHER-ID";
    private static final String PRIVACY_URL = "YOUR-PRIVACY-URL";
    private static final String MARKET_URL_PAID_VERSION = "market://details?id=com.example.app.pro";

    private final Context context;

    private ConsentForm consentForm;

    public GdprHelper(Context context) {
        this.context = context;
    }

    // Initialises the consent information and displays consent form if needed
    public void initialise() {
        ConsentInformation consentInformation = ConsentInformation.getInstance(context);
        consentInformation.requestConsentInfoUpdate(new String[]{PUBLISHER_ID}, new ConsentInfoUpdateListener() {
            @Override
            public void onConsentInfoUpdated(ConsentStatus consentStatus) {
                // User's consent status successfully updated.
                if (consentStatus == ConsentStatus.UNKNOWN) {
                    displayConsentForm();
                }
            }

            @Override
            public void onFailedToUpdateConsentInfo(String errorDescription) {
                // Consent form error. Would be nice to have proper error logging. Happens also when user has no internet connection
                if (BuildConfig.BUILD_TYPE.equals("debug")) {
                    Toast.makeText(context, errorDescription, Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    // Resets the consent. User will be again displayed the consent form on next call of initialise method
    public void resetConsent() {
        ConsentInformation consentInformation = ConsentInformation.getInstance(context);
        consentInformation.reset();
    }

    private void displayConsentForm() {

        consentForm = new ConsentForm.Builder(context, getPrivacyUrl())
                .withListener(new ConsentFormListener() {
                    @Override
                    public void onConsentFormLoaded() {
                        // Consent form has loaded successfully, now show it
                        consentForm.show();
                    }

                    @Override
                    public void onConsentFormOpened() {
                        // Consent form was displayed.
                    }

                    @Override
                    public void onConsentFormClosed(
                            ConsentStatus consentStatus, Boolean userPrefersAdFree) {
                        // Consent form was closed. This callback method contains all the data about user's selection, that you can use.
                        if (userPrefersAdFree) {
                            redirectToPaidVersion();
                        }
                    }

                    @Override
                    public void onConsentFormError(String errorDescription) {
                        // Consent form error. Would be nice to have some proper logging
                        if (BuildConfig.BUILD_TYPE.equals("debug")) {
                            Toast.makeText(context, errorDescription, Toast.LENGTH_LONG).show();
                        }
                    }
                })
                .withPersonalizedAdsOption()
                .withNonPersonalizedAdsOption()
                .withAdFreeOption()
                .build();
        consentForm.load();
    }

    private URL getPrivacyUrl() {
        URL privacyUrl = null;
        try {
            privacyUrl = new URL(PRIVACY_URL);
        } catch (MalformedURLException e) {
            // Since this is a constant URL, the exception should never(or always) occur
            e.printStackTrace();
        }
        return privacyUrl;
    }

    private void redirectToPaidVersion() {
        Intent i = new Intent(
                Intent.ACTION_VIEW,
                Uri.parse(MARKET_URL_PAID_VERSION));
        context.startActivity(i);
    }

}

This is as per the link: Google consent SDK

As per my understanding, The behaviour of the above code would be like as below:

1. For European User:

i) If the internet is connected: User will be shown the consent form before start of the application.

ii) If the internet is not connected: User will not be shown the consent form and will be navigated to the first page of the application directly. If the user connect internet in between then too user will not be shown consent form.

2. For Non European User:

i) If the internet is connected: User will not be shown the consent form before start of the application.

ii) If the internet is not connected: User will not be shown the consent form and application will run. If the user connect internet in between then too user will not be shown consent form.

My Question is as below:

I have doubt for the case when the user is European and it is not connected to the internet. Now the consent form will not be shown. Now if the user enable internet in between the application, then do we need to take the consent at that time explicitly.

Or Let the user to give the consent by clicking on the given option(reset) in the app.

manish bansal
  • 136
  • 1
  • 6

1 Answers1

0

Before loading ads i check if the ConsentStatus is either Personalized or Non Personalized.

If there is no internet connection, then the ConsentStatus would be Unknown and my ads won't load which is indeed a way to bypass ads on apps, but i'm not sure what we can do against this.

if (ConsentInformation.getInstance(this).getConsentStatus() == ConsentStatus.NON_PERSONALIZED){
            Bundle extras = new Bundle();
            extras.putString("npa", "1");

            adRequest = new AdRequest.Builder()
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .addNetworkExtrasBundle(AdMobAdapter.class, extras)
                    .build();

            adLoader.loadAd(adRequest);
}else if(ConsentInformation.getInstance(this).getConsentStatus() == ConsentStatus.PERSONALIZED){
            adRequest = new AdRequest.Builder()
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .build();
            adLoader.loadAd(adRequest);
}

EDIT

GDPR is only for EU, so check in onConsentInfoUpdated if the user is in the EU or if the consent status is Unknown like this:

@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
      // User's consent status successfully updated.
      if (consentStatus == ConsentStatus.UNKNOWN) {     
           if(ConsentInformation.getInstance(mContext).isRequestLocationInEeaOrUnknown()) {
              displayConsentForm();
      }else{  
          ConsentInformation.getInstance(mContext).setConsentStatus(ConsentStatus.PERSONALIZED);
      }
   }                       
}
Vince VD
  • 1,506
  • 17
  • 38