December 31, 2019 /   java   android   admob   facebook audence network   apps   monetisation   revenue

Want to optimise your ad revenue from android apps?

Most of android beginners use Google's AdMob for monetisation. But AdMob's fill rate may hamper your revenue.

A fill rate is how many ad requests got filled of all requests made.

You can mix some of best ad providers in your app to get most of your app's traffic.

Facebook Audience Network is another good choice of ad provider network. It gives you higher eCPM.

You can quick start Facebook Audience Netowk by creating an account on https://business.facebook.com/ and you can learn using admob from https://admob.google.com/

Here is an example of using Facebook Audience Network when AdMob fails to serve your ad request.

public class SomeActivity extends AppCompatActivity {

    private InterstitialAd mInterstitialAd;
    private com.facebook.ads.InterstitialAd fbIntAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_page);
        initAdMobInt();
        initFBIntAd();
        TextView showAds =  findViewById(R.id.show_ads);
        showAds.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (fbIntAd.isAdLoaded()
                        && !fbIntAd.isAdInvalidated()) {
                    fbIntAd.show();
                } else if (mInterstitialAd.isLoaded()) {
                    adMobIntAd.show();
                }   else {
                    // perform required action
                }

            }
        });
    }

    private void initAdMobInt() {
        adMobIntAd = new InterstitialAd(this);
        adMobIntAd.setAdUnitId(getString(R.string.admob_int_ad));
        adMobIntAd.loadAd(new AdRequest.Builder().build());

        adMobIntAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                // Load the next interstitial.
                adMobIntAd.loadAd(new AdRequest.Builder().build());
                // Perform the action here
            }

            @Override
            public void onAdFailedToLoad(int i) {
                adMobIntAd.loadAd(new AdRequest.Builder().build());
            }

            @Override
            public void onAdLeftApplication() {
                adMobIntAd.loadAd(new AdRequest.Builder().build());
            }
        });
    }

    private void initFBIntAd() {
        fbIntAd = new com.facebook.ads.InterstitialAd(this, getString(R.string.fb_int_ad));
        // Set listeners for the Interstitial Ad
        fbIntAd.setAdListener(new InterstitialAdListener() {
            @Override
            public void onInterstitialDisplayed(Ad ad) {
            }

            @Override
            public void onInterstitialDismissed(Ad ad) {
                //Perform action here .....
                fbIntAd.loadAd();
            }

            @Override
            public void onError(Ad ad, AdError adError) {
                // Ad error callback
                fbIntAd.loadAd();
            }

            @Override
            public void onAdLoaded(Ad ad) {
            }

            @Override
            public void onAdClicked(Ad ad) {
                // Ad clicked callback
            }

            @Override
            public void onLoggingImpression(Ad ad) {
                // Ad impression logged callback
            }
        });

        fbIntAd.loadAd();
    }

}

Gradle build dependencies for ad networks

implementation 'com.google.android.gms:play-services-ads:11.4.2'
implementation 'com.facebook.android:audience-network-sdk:5.3.0-beta2'

Related Posts

Android: Integrating Facebook Audience Network (FAN)

How to implement AdMob's Interstitial Ad the Right Way in Android Apps?