January 13, 2020 /   facebook audience network   AdMob   Android   Java

A sample facebook audience network monetisation dashboard.

Facebook Audience Network

AdMob has always been a first choice for monetisation in Android Apps. Facebook Audience Network (FAN) is also a good choice to start with.

Advantages of using Facebook Audience Network -

  1. You can start monetising from day 1.
  2. There is no need to verify your address unlike Google's AdMob.

Facebook audience network have some disadvantages as well, like low fill rate. Actually facebook fills ads on the basis of target's facebook activity. So if a person does not have facebook account, fill rate for that person will be zero.

Beside that FAN has good eCPM(Estimated revenue per thousand impressions). You can set eCPM limits per ad format to maximise your revenue.

Using Facebook Audience Network

To Use FAN you need to create a business account on

https://business.facebook.com/

Enter your personal details, your business details and bank account number to receive money.

After you have successfully created your business account, create your first app using appropriate options. Here are some sample screens.

Then Create a Banner Placement

After creation you will get a placement id

Platform:Android app
Format:Banner
Placement ID:323434432478226_4858336699144666

This placement ID need to be written in your string.xml constants file.

Facebook Audience Network SDK

Add following dependency to your app's build.gradle file

    implementation 'com.facebook.android:audience-network-sdk:5.+'

Facebook Audience Network Ad Formats

FAN provides popular Banner, Medium Rectangle and Interstitial ad formats.

Banner Ads

Banner Ads are small, rectangular ads that are placed generally on the bottom of screen

Implementation

Put bellow code on the bottom in your layout XML file in which you want to place the banner ad.

<LinearLayout
        android:id="@+id/fb_banner_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.1"
        android:orientation="vertical"
        android:layout_marginTop="10dp"
        android:layout_alignParentBottom="true"
        />

Height weight is 0.1 assuming your main content has weight 0.9.

Write bellow code in your Activity to load the banner ad.

//Required imports
import import com.facebook.ads.*;
// Your activity methods
// ....
@Override
protected void onCreate(Bundle savedInstanceState) { 
        ....

        adView = new AdView(this, getString(R.string.fb_banner_id), AdSize.BANNER_HEIGHT_50);
        // Find the Ad Container
        LinearLayout adContainer = (LinearLayout) findViewById(R.id.fb_banner_container);

        // Add the ad view to your activity layout
        adContainer.addView(adView);

        // Request an ad
        adView.loadAd();
        ...
}

Medium Rectangle

Medium Rectangles are banner ads that occupy more space that normal banner ads.

Implementation

Create a Placement ID of type medium rectangle on monetisation manager account.

Create an Ad container in xml

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/medium_rectangle_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginBottom="10dp"
    card_view:cardCornerRadius="@dimen/cardview_default_radius"
    card_view:contentPaddingTop="10dp"
    card_view:contentPaddingBottom="10dp"
    card_view:cardBackgroundColor="@android:color/transparent"
    card_view:cardElevation="0dp"
    />

Load Ad in java

        adView = new AdView(this, getString(R.string.medium_rectangle_palacement_id),
                AdSize.BANNER_HEIGHT_50);
        // Find the Ad Container
        LinearLayout adContainer = (LinearLayout) findViewById(R.id.medium_rectangle_container);

        // Add the ad view to your activity layout
        adContainer.addView(adView);

        // Request an ad
        adView.loadAd();

Interstitial Ads

Interstitial Ads are full screen ads that pop up on a button click or navigation.

There is no need for a view in xml to show this kind of ad. Here's how in Java you can load an Interstitial ad upon a click of button.

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_page);
        ....
        initializeIntstitalAd();
        shareButton = findViewById(R.id.share);
        shareButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (interstitialAd.isAdLoaded() &&
                        !interstitialAd.isAdInvalidated()) {
                    interstitialAd.show();
                } else {
                    performAction();
                }
            }
        });

}
private void initializeIntstitalAd() {
        interstitialAd = new InterstitialAd(ActionActivity.this, getString(R.string.fb_interstital_placement_id));
        // Set listeners for the Interstitial Ad
        interstitialAd.setAdListener(new InterstitialAdListener() {
            @Override
            public void onInterstitialDisplayed(Ad ad) {
            }

            @Override
            public void onInterstitialDismissed(Ad ad) {
                performAction();
                interstitialAd.loadAd();
            }

            @Override
            public void onError(Ad ad, AdError adError) {
                // Ad error callback
                interstitialAd.loadAd();
                Toast.makeText(ActionActivity.this, "int ad load failed "+ adError.getErrorMessage(), Toast.LENGTH_LONG).show();
            }

            @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
            }
        });

        // For auto play video ads, it's recommended to load the ad
        // at least 30 seconds before it is shown
        interstitialAd.loadAd();
    }

Related Posts

Android: Using together AdMob and Facebook Audience Network

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