How to pass user consent to AdMob (GDPR)

2.6k views Asked by At

I'm using AdMob to serve ads to users in EU. The documentation states that I can pass the user consent status by the following line of code:

AdRequest request = new AdRequest.Builder() .AddExtra("npa", "1") .Build();

The problem is that this line does not compile. There is no such function as AddExtra on the AdRequst object. I do use the latest AdMob library available.

  implementation 'com.google.android.gms:play-services-ads:15.0.1'
  implementation 'com.google.firebase:firebase-ads:15.0.1'

So, how do I actually pass this "npa" value to AdMob.

Anyone?

1

There are 1 answers

2
Dhaval Solanki On BEST ANSWER

you can add npa using addNetworkExtrasBundle method which like bellow

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

        AdRequest addRequest = new AdRequest.Builder()
                .addNetworkExtrasBundle(AdMobAdapter.class, bundleExtra)
                .build();

And also please check bellow official link
https://developers.google.com/admob/android/eu-consent#forward_consent_to_the_google_mobile_ads_sdk