Requesting Consent from European Users

Under the Google EU User Consent Policy, you must make certain disclosures to your users in the European Economic Area (EEA) and obtain their consent to use cookies or other local storage, where legally required, and to use personal data (such as AdID) to serve ads. This policy reflects the requirements of the EU ePrivacy Directive and the General Data Protection Regulation (GDPR). To support publishers in meeting their duties under this policy, Google offers a Consent SDK.

Ads served by Google can be categorized as personalized or non-personalized, both requiring consent from users in the EEA. By default, ad requests to Google serve personalized ads, with ad selection based on the user's previously collected data. Google also supports configuring ad requests to serve non-personalized ads. Learn more about personalized and non-personalized ads.

This guide describes how to use the Consent SDK to obtain consent from users. It also describes how to forward consent to the Google Mobile Ads SDK once you have obtained consent.

Prerequisites

The Consent SDK is an open-source library that provides utility functions for collecting consent from your users. The full source code will be made available on GitHub by mid-May.

When using the Consent SDK, it is recommended that you determine the status of a user's consent at every app launch. To do this, call requestConsentInfoUpdate() on an instance of ConsentInformation.

import com.google.ads.consent;

public class MainActivity extends Activity {
    ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        ConsentInformation consentInformation = ConsentInformation.getInstance();
        String[] publisherIds = {"pub-0123456789012345"};
        consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
            @Override
            public void onConsentInfoUpdated(ConsentStatus consentStatus) {
                 // User's consent status successfully updated.
            }

            @Override
            public void onFailedToUpdateConsentInfo(String errorDescription) {
                 // User's consent status failed to update.
            }
        });
        ...
    }
    ...
}

The call to requestConsentInfoUpdate() requires two arguments:

  • An array of publisher IDs that your app requests ads from. Find your publisher ID.

  • An instance of ConsentInfoUpdateListener.

If the consent information is successfully updated, the updated consent status is provided via the onConsentInfoUpdated() method of the ConsentInfoUpdateListener. The returned ConsentStatus may have the values listed below:

Consent Status Definition
ConsentStatus.PERSONALIZED_ADS The user has granted consent for personalized ads.
ConsentStatus.NON_PERSONALIZED_ADS The user has granted consent for non-personalized ads.
ConsentStatus.UNKNOWN The user has neither granted nor declined consent for personalized or non-personalized ads.

Once consent information is successfully updated, you can also check ConsentInformation.getInstance().isRequestLocationInEeaOrUnknown() to see if the user is located in the European Economic Area or the request location is unknown.

If the isRequestLocationInEeaOrUnknown() method returns false, the user is not located in the European Economic Area and consent is not required under the EU User Consent Policy. You can make ad requests to the Google Mobile Ads SDK.

If the isRequestLocationInEeaOrUnknown() method returns true:

Google's Consent SDK provides two ways to collect consent from a user:

Remember to provide users with the option to Change or revoke consent.

The Google-rendered consent form is a full-screen configurable form that displays over your app content. You can configure the form to present the user with combinations of the following options:

  • Consent to view personalized ads
  • Consent to view non-personalized ads
  • Use a paid version of the app instead of viewing ads

You should review the consent text carefully: what appears by default is a message that might be appropriate if you use Google to monetize your app; but we cannot provide legal advice on the consent text that is appropriate for you. To update consent text of the Google-rendered consent form, modify the consentform.html file included in the Consent SDK as required.

The Google-rendered consent form is configured and displayed using the ConsentForm class. The following code demonstrates how to build a ConsentForm with all three consent options:

ConsentForm form = new ConsentForm.Builder(Context context)
    .withListener(new ConsentFormListener() {
        @Override
        public void onConsentFormLoaded() {
            // Consent form loaded successfully.
        }

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

        @Override
        public void onConsentFormClosed(
                ConsentStatus consentStatus, Boolean userPrefersAdFree) {
            // Consent form was closed.
        }

        @Override
        public void onConsentFormError(String errorDescription) {
            // Consent form error.
        }
    })
    .withPersonalizedAdsOption()
    .withNonPersonalizedAdsOption()
    .withAdFreeOption()
    .build();

The methods above prepare the Google-rendered consent form with the following options:

withListener()
Registers a listener for the ConsentForm. Each of the overridable methods in ConsentFormListener corresponds to an event in the life-cycle of the consent form.
Overridable methods
onConsentFormLoaded The consent form successfully loaded.
onConsentFormError The consent form failed to load. The errorDescription parameter provides a description of the error.
onConsentFormOpened The consent form was opened.
onConsentFormClosed The consent form was closed. The parameters of the method provides the following information:
  • consentStatus is a ConsentStatus value that describes the updated consent status of the user.
  • userPrefersAdFree has a value of true when the user chose to use a paid version of the app instead of viewing ads.
withPersonalizedAdsOption()
Indicates that the consent form should show a personalized ad option.
withNonPersonalizedAdsOption()
Indicates that the consent form should show a non-personalized ad option.
withAdFreeOption()
Indicates that the consent form should show an ad-free app option.

Once you have created a ConsentForm object, load the consent form by invoking the load() method of ConsentForm, as shown below:

form.load();

To present the user with the Google-rendered consent form, call show() on an instance of ConsentForm, as demonstrated below:

form.show();

After the user selects an option and closes the form, the Consent SDK saves the user's choice and fires the onConsentFormClosed event. You can listen for this event and forward consent to the Google Mobile Ads SDK.

If you choose to collect consent yourself, you can use the getAdProviders() method of the ConsentInformation class to get the ad technology providers associated with the publisher IDs used in your app. Note that consent is required for the full list of ad technology providers configured for your publisher IDs.

List<AdProvider> adProviders = ConsentInformation.getInstance().getAdProviders();

You can then use the list of ad technology providers to obtain consent yourself.

Upon getting consent, record the ConsentStatus corresponding to the user's response using the setConsentStatus() method of the ConsentInformation class.

ConsentInformation.getInstance().setConsentStatus(ConsentState.PERSONALIZED_ADS);

After reporting consent to the Consent SDK, you can forward consent to the Google Mobile Ads SDK.

It is important that the user is able to change or revoke the consent they have provided at any time. To allow users to update their consent, simply repeat the steps outlined in the Collect consent section when the user chooses to update their consent status.

If a publisher is aware that the user is under the age of consent, all ad requests must set TFUA (Tag For Users under the Age of Consent in Europe). To include this tag on all ad requests made from your app, call setTagForUnderAgeOfConsent(true). This setting takes effect for all future ad requests.

ConsentInformation.getInstance().setTagForUnderAgeOfConsent(true);

Once the TFUA setting is enabled, the Google rendered consent form will fail to load. All ad requests that include TFUA will be made ineligible for personalized advertising and remarketing. TFUA disables requests to third-party ad technology providers, such as ad measurement pixels and third-party ad servers.

To remove TFUA from ad requests, call setTagForUnderAgeOfConsent(false).

The default behavior of the Google Mobile Ads SDK is to serve personalized ads. If a user has consented to receive only non-personalized ads, you can configure an AdRequest object with the following code to specify that only non-personalized ads should be returned:

Bundle extras = new Bundle();
extras.putString("npa", "1");

AdRequest request = new AdRequest.Builder()
        .addNetworkExtrasBundle(AdMobAdapter.class, extras)
        .build();

Send feedback about...

Google Mobile Ads SDK for Android
Google Mobile Ads SDK for Android
Need help? Visit our support page.