Monday, May 3, 2021

How NOT TO get banned from AdMob for 'click fraud'

  1. During development: use the test ad unit id. 
  2. For release: add test device(s) to your AdMob account.

As simple as that. In more details:

1. During development: use test ad unit id

Following  the AdMob integration instructions, you will be provided with the test ad unit id. Obviously, you will not hard-code it in your app, you will access it just like any other string resource - via Activity.getString method.

The example might be the following:

String    adId      = getString(R.string.ad_unit_id);
AdRequest adRequest = new AdRequest.Builder().build();

RewardedInterstitialAd.load(this, adId, adRequest,
new RewardedInterstitialAdLoadCallback() { ... });

Here I am creating a rewarded interstitial ad, but principle is the same for any other type of ads - banner, interstitial or native. 

Now we will place the given test ad unit id in a resource file, donottranslate.xml being an ideal candidate for that:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ad_unit_id">ca-app-pub-xxxxxxxxxxxxxxxx/x...</string>
</resources>

Instead of placing this file in /src/main/res/values folder we'll put it in /src/debug/res/values (create it if it doesn't exist). 

This string resource will now exist only when we are building a debug version of our app, so we need to do the similar thing for a release version. We will create the folder (path) /src/release/res/values and we will put another donottranslate.xml file inside. This file will look exactly the same as the previous one, except that you will replace the test ad unit id with the real one that you got when you have created an ad. Your project structure should look something like this:

We're done regarding this part! Our debug builds will use the test ad and release builds the real one. Now let's get ourselves covered and make sure that we are not shown a real ad when we are testing a release build on our device(s).

2. For release: add test device(s) to your AdMob account

Once you are logged in your AdMob account, on the left hand side, close to the bottom of the navigation bar, open Settings and then Test Devices tab. Click on the Add Test Device button and fill out the form. Voila!

  

This blog post was inspired by the following blog post: Never run Google ads if you have an Android app, especially by its subtitle: Google can and will permanently ban your Android app if Google thinks you’ve clicked on your own ads. This does not need to happen and, as it has been shown, accident of clicking (or even watching) your own ads can be easily prevented.

No comments:

Post a Comment