FeedAd MoPub Integration

Deprecation Notice

MoPub has been aquired by AppLovin. The FeedAd MoPub plugin will not receive further updates in favor of our AppLovin MAX Plugin.

The FeedAd Android SDK can be easily combined with the MoPub SDK for Android. All you have to do for this, is to add a dependency to our MoPub plugin that adds the adapter classes.

To see an example, please check out our Android demo app.

Quick Start

If you are familiar with adding and configuring 3rd party networks with MoPub, the following points have all the information you will need. Otherwise, just continue reading for a step-by-step guide.

Component Configuration Options
Plugin Dependency implementation('com.feedad.android:feedad-mopub:1.0-4') none
Adapter Configuration class com.mopub.mobileads.FeedAdMoPubAdapter clientToken: String required
enableLogging: "true","false" optional
waitForConsent: "true","false" optional
Banner Event Class com.mopub.mobileads.FeedAdMoPubAd as JSON:
placementId: String required
collapseAfterPlay: "true","false" optional
Interstitial Event Class com.mopub.mobileads.FeedAdMoPubInterstitialAd as JSON:
placementId: String required
cancelable: "true","false" optional
Native Event Class com.mopub.mobileads.FeedAdMoPubNativeAd as JSON:
placementId: String required
collapseAfterPlay: "true","false" optional
Native Ad Renderer com.mopub.mobileads.FeedAdMoPubNativeAdRenderer adUnitId: String required
Placeholder Image Style <item name="mopubFeedAdPlaceholderImage">...</item> drawable or color resource

Placement ID?

You can choose placement IDs yourself. A placement ID should be named after the ad position inside your product. For example, if you want to display an ad inside a list of news articles, you could name it "ad-news-overview".
A placement ID may consist of lowercase a-z, 0-9, - and _. You do not have to manually create the placement IDs before using them. Just specify them within the code, and they will appear in the FeedAd admin panel after the first request. Learn more about Placement IDs and how they are grouped to play the same Creative

Step-By-Step

1. Dependencies

Make sure that the FeedAd SDK, MoPub SDK, and the FeedAd MoPub Plugin are all inside your build.gradle dependencies section.

dependencies {
    // any recent MoPub version will do
    implementation('com.mopub:mopub-sdk:5.18.0@aar') {
        transitive = true
    }
    implementation('com.feedad.android:feedad-sdk:1.4.13') {
        transitive = true
    }
    implementation('com.feedad.android:feedad-mopub:1.0-4')
}

2. SDK Configuration

Add the following code to the initialization of the MoPub SDK:

// FeedAd Init Parameters
Map<String, String> parameters = new HashMap<>();
parameters.put("clientToken", "your-client-token"); // required
parameters.put("waitForConsent", "true"); // optional, force FeedAd to wait for TCF 2.0 consent
parameters.put("enableLogging", "true"); // optional, make FeedAd log into logcat

// Add FeedAd to the mediation networks
SdkConfiguration config = new SdkConfiguration.Builder(bannerAdUnit)
    .withAdditionalNetwork(FeedAdMoPubAdapter.class.getName())
    .withMediatedNetworkConfiguration(FeedAdMoPubAdapter.class.getName(), parameters)
    .build();

// Initialize MoPub
MoPub.initializeSdk(activity, config, ...);

Parameters

Name Values Description
clientToken String required, the FeedAd client token of your FeedAd publisher account.
enableLogging "true", "false" optional if the FeedAd SDK will print debug messages into the logcat.
waitForConsent "true", "false" optional, forces FeedAd to wait for TCF 2.0 consent.
Not required if MoPub is initialized after consent has been fetched.
Do not activate this outside of TCF legislation as it will prevent ad playback.

3. Adapter Configuration

Configure your line-items depending on which type of ad you want to integrate.

Interstitial Ads

Interstitial Config

Custom event class:
com.mopub.mobileads.FeedAdMoPubInterstitialAd

Custom event data:
All values need to be encoded as valid JSON with string values.

{
    "placementId": "your-placement-id",
    "cancelable": "true"
}
Parameter Values Description
placementId String required, the placement ID for the interstitial ad.
cancelable "true", "false" optional if the user can cancel the interstitial at any time by pressing the back button. (default: false)

Interstitial Config

Custom event class:
com.mopub.mobileads.FeedAdMoPubAd

Custom event data:
All values need to be encoded as valid JSON with string values.

{
    "placementId": "your-placement-id",
    "collapseAfterPlay": "true"
}
Parameter Values Description
placementId String required, the placement ID for the interstitial ad.
collapseAfterPlay "true", "false" optional if you want the ad view to either collapse to a height of zero after playing the ad or to remain the same size. (default: false)

Native Ads

Interstitial Config

Custom event class:
com.mopub.mobileads.FeedAdMoPubNativeAd

Custom event data:
All values need to be encoded as valid JSON with string values.

{
    "placementId": "your-placement-id",
    "collapseAfterPlay": "true"
}
Parameter Values Description
placementId String required, the placement ID for the interstitial ad.
collapseAfterPlay "true", "false" optional if you want the ad view to either collapse to a height of zero after playing the ad or to remain the same size. (default: false)

Native Ad Renderer:

Add the class FeedAdMoPubNativeAdRenderer(String nativeAdUnit) as a renderer to your MoPub native ad integration. The parameter nativeAdUnit is the MoPub ad unit ID for the native ad placement.

4. Customize Placeholder Image

This does not affect interstitial ads.

You can specify a placeholder drawable that is shown inside the ad view if FeedAd has completed its ad playback and the view is still visible. This is required because of a minor conflict between how MoPub and FeedAd display ads:

  1. MoPub shows banner ads for a fixed duration (rotation interval) or indefinitely.
  2. MoPub shows native ads indefinitely.
  3. FeedAd plays mostly video ad playlists with videos of different lengths.
  4. MoPub lacks the ability to trigger the reloading of an ad view from within an adapter.

This can cause a situation wherein FeedAd has no more ads to play but is still visible within the MoPub ad view. For example:

  1. MoPub loads FeedAd into a banner view with a 40s rotation interval.
  2. FeedAd plays a playlist of a 20s and 15s long videos.
  3. When FeedAd completes its playlist, the ad view will still be visible for 5s until it reloads.

Those 5 seconds can be filled with a given placeholder drawable or color. If none is given, FeedAd will default to gray.

You can specify this drawable (or color) within your app's main theme:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- ... -->
    <item name="mopubFeedAdPlaceholderImage">@drawable/some_drawable</item>
    <!-- or -->
    <item name="mopubFeedAdPlaceholderImage">@color/some_color</item>
</style>