简体   繁体   中英

Enabling test ads by ip for Google AdSense

To run Google's pre-launch report without clicking on ads I want to add all the devices as exceptions. They give me the ip's here: https://firebase.google.com/docs/test-lab/overview#testlab_and_mobile_advertising

"following IP address blocks: 108.177.6.0/24 (for physical devices) and 104.196.0.0/16 (for virtual devices)"

However, I can't seem to figure out how to block that with Google AdSense.

Currently my code is like this

ad = new AdRequest.Builder()
.addTestDevice("XXXXXXX")
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();

But this doesn't work. What am I doing wrong?

IP addresses are not device IDs - you can't use an IP address this way.

You can know if your app is running in Test Lab by using the bit of code on this page that checks a system property: https://firebase.google.com/docs/test-lab/android-studio

String testLabSetting =
  Settings.System.getString(context.getContentResolver(), "firebase.test.lab");
if (testLabSetting.equals("true")) {
  // Do something when running in Test Lab
}

So what you can do instead is use this to determine if ads should be displayed at all. You could go further and use this to build your own (decorated) AdRequest object that correctly returns false for isTestDevice() when running in Test Lab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM