InterstitialAd implementation example (AdMob) that should never be done

I will expose a bad implementation example of interstitial advertising that I have been confused about. I'm reflecting on it now.

Code that should not be imitated

MainActivity.java


public class MainActivity extends AppCompatActivity {
    private InterstitialAd mInterstitialAd;
    private boolean exitFlg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        exitFlg = false;

        MobileAds.initialize(this, "ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx");
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-yyyyyyyyyyyyyyyy/yyyyyyyyyy");
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                super.onAdClosed();
                //Close the app when the interstitial ad is closed
                exitFlg = true;
                onBackPressed();
            }
        });
        if (new Random().nextInt(10) % 3 == 0) {
            // 40%Probability of ad loading
            mInterstitialAd.loadAd(new AdRequest.Builder().build());
        }
    }

    @Override
    public void onBackPressed() {
        //There is no Navigation Drawer etc., and it is assumed that the application can be closed with one back button
        if (!exitFlg && mInterstitialAd.isLoaded()) {
            //If the exit flag is false and the ad is loaded, display an interstitial ad
            mInterstitialAd.show();
        } else {
            //Otherwise close the app
            super.onBackPressed();
        }
    }
}

I just thought that I should call super.onBackPressed () in ʻonAdClosed () without using ʻexitFlg. However, it is useless to try it, so I will post an excerpt of the code I was actually using. It's embarrassing.

What's wrong?

AdMob's Prohibitions on the introduction of interstitial ads states:

Interstitial ads should not be displayed when the app loads or exits. Display is permitted only when the content (page) of the application is switched. In addition, it is not permitted to display ads on apps running in the background of the device or to display ads outside the app environment. Users need to be clear about which app the ad was displayed on.

That's really true. It's hard to see that usability is our number one priority. The timing to close an app can also be the timing to move to another app. Interfering with the operation is offensive to the user and annoying to the advertiser.

Why did you do it?

I lost my greed that I might make a little profit. There are other apps that are doing it (I'm not sure if I'm using AdMob, I haven't looked at the rules for ad networks other than AdMob), and I'm wondering if it's okay to reduce the frequency of display. I was convinced myself. At that time, I was stupid even though I was reading the above prohibited items. I also wanted to experiment, so I was moving with a stupid idea of trying and making decisions.

As a result, there was almost no revenue from interstitial ads, and there was a two-star review saying "too many ads", and the uninstall rate seemed to be high, so I think there was no merit. I'm digging hard now.

If you read this article, don't make the same mistake

I'm posting it for self-discipline, but if you read it and are thinking about implementing some kind of advertisement, please make me a teacher. Follow the rules and improve usability. I have no regrets. Qiita has a "Like" button, but if you like it in this article, I think it's bad, and I'd like to work even harder to become a serious developer. ..

excuse me.

Recommended Posts

InterstitialAd implementation example (AdMob) that should never be done
Settings that should be done when operating a production environment with Rails