Enable MoPub Mediation on Android

Use this guide to add the Vungle Android SDK to your app, using MoPub as your main advertising mediation layer. MoPub Android adapter 6.8.1.0 is compatible with Vungle Android SDK 6.8.1.

Before You Begin

CCPA

As of July 1, 2020, the California Consumer Privacy Act (CCPA) is enforced and publishers must update to Vungle Android SDK v6.7.0 and MoPub adapter v6.7.0.0 to comply with CCPA.

To pass CCPA values, call the Vungle SDK API directly. This is the only feature that should be accessed directly through Vungle SDK API. Other optional features such as Android ID and memory settings should use VungleAdapterConfiguration class provided in the adapter.

Use Vungle.updateCCPAStatus to set the user’s consent status; specify that the user has opted out by passing Vungle.Consent.OPTED_OUT. Use Vungle.getCCPAStatus to get the current CCPA status for a particular user.

CCPA API
updateCCPAStatus getCCPAStatus
public static void updateCCPAStatus(@NonNull final Vungle.Consent status)
Sample Code
// To set the user's CCPA status to opted out:
Vungle.updateCCPAStatus(Vungle.Consent.OPTED_OUT);
// To find out what the user's current consent status is:
Vungle.Consent currentCCPAStatus = Vungle.getCCPAStatus();

Banner Ad

Vungle supports following banner ad sizes: Banner, MREC, Leaderboard. Use an ad container that is no smaller than the specified size, and use the corresponding MoPubView.MoPubAdSize height value when loading banner ads. Note that the MREC (300dp x 250dp) format must have its own, separate placement reference ID. An MREC format must be configured as 'MREC' in the Vungle dashboard, as opposed to the way that multiple banner sizes can all be configured under the same placement ID as 'banner'.

MoPubAdSize Size
HEIGHT_50 320dp x 50dp
HEIGHT_90 728dp x 90dp
HEIGHT_250 300dp x 250dp
HEIGHT_280 300dp x 250dp
MATCH_VIEW Closest size that will fit in the view container

Sample code

@Override
public MoPubView.MoPubAdSize getAdSize() {
    return MoPubView.MoPubAdSize.HEIGHT_250;
}

Optional Advanced Settings

Early SDK Initialization (Recommended)

MoPub Android SDK v5.5.0 and higher allows you to early initialize ad network SDK when the MoPub SDK completes initialization. We strongly recommend you to use this feature because it will allow additional time for the Vungle SDK to pre-cache an ad and have it ready to play at the next display opportunity.

Sample code

SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Map<String, String> vungleSettings = new HashMap<>();

vungleSettings.put("appId", "YOUR_VUNGLE_APP_ID");

SdkConfiguration configBuilder = new SdkConfiguration.Builder("MOPUB_AD_UNIT_WITH_VUNGLE_PLACEMENT")
        .withMediatedNetworkConfiguration(VungleAdapterConfiguration.class.getName(), vungleSettings)
        .build();

MoPub.initializeSdk(this, configBuilder, initSdkListener());

Memory Settings

Starting with Vungle SDK v6.4.0, you can prevent the SDK from downloading, requesting ads, or even initializing if the storage of your Android device falls below a predefined threshold.

These are the option keys available:

Keys

Type/Value

Description

pre_key_min_space_for_init

String, value in bytes (default 51 MB)

Sets the required minimum available free storage space to be able to initialize the SDK

pre_key_min_space_for_ad

String, value in bytes (default 50 MB)

Sets the required minimum available free storage space to be able to request an ad

 

Sample code

Map<String, String> vungleSettings = new HashMap<>();

vungleSettings.put("appId", "YOUR_VUNGLE_APP_ID");

vungleSettings.put("VNG_MIN_SPACE_INIT",
        mPreferences.getString("pref_key_min_space_for_init", String.valueOf(20 * 1024 * 1024)));
vungleSettings.put("VNG_MIN_SPACE_LOAD_AD",
        mPreferences.getString("pref_key_min_space_for_ad", String.valueOf(20 * 1024 * 1024)));

Restrict Use of Device ID

Starting with Vungle SDK v6.4.10 and onward, you can now restrict the SDK from passing the Android ID from the device to the SDK.

Map<String, String> vungleSettings = new HashMap<>();

vungleSettings.put("appId", "YOUR_VUNGLE_APP_ID");

vungleSettings.put("VNG_DEVICE_ID_OPT_OUT",
        String.valueOf(mPreferences.getBoolean("pref_key_key_android_id_opted_out", true)));

Interstitial Ads

You can pass custom ad configuration settings to customize your ad experience when load is issued for MoPubInterstitial. Note that VungleMediationSettings has been deprecated as of Vungle SDK v6.5.1.0 and replaced with VungleMediationConfiguration.

Attribute

Default Value

Description

withStartMuted

true

Play ad with sound muted or unmuted. Set to 'true' to play muted. Set to 'false' to play with sound.

withAutoRotate AdConfig.AUTO_ROTATE

Available Orientation:

  • AdConfig.AUTO_ROTATE
  • AdConfig.PORTRAIT
  • AdConfig.LANDSCAPE
  • AdConfig.MATCH_VIDEO

Example

VungleMediationConfiguration vungleMediationConfiguration = new VungleMediationConfiguration.Builder()
    .withAutoRotate(AdConfig.LANDSCAPE) 
    .withStartMuted(true) 
    .build();
mMoPubInterstitial.setLocalExtras(vungleMediationConfiguration.getExtrasMap());
mMoPubInterstitial.load();

Rewarded Ads

You can pass custom ad configuration to customize your ad experience when load is issued for MoPubRewardedVideos. Note that VungleMediationSettings has been deprecated as of Vungle SDK v6.5.1.0 and replaced with VungleMediationConfiguration.

Attribute

Default Value

Description

withUserId

null

Sets the unique user ID to pass to your application to verify that this user should be rewarded for watching an incentivized ad.

withStartMuted

false

Sets the starting sound state for the ad. If 'false', the audio respects device volume and sound settings. If 'true', video begins muted but user may modify.

withAutoRotate

AdConfig.AUTO_ROTATE

Available Orientation:

  • AdConfig.AUTO_ROTATE
  • AdConfig.PORTRAIT
  • AdConfig.LANDSCAPE
  • AdConfig.MATCH_VIDEO

Example

VungleMediationConfiguration vungleMediationConfiguration = new VungleMediationConfiguration.Builder()
        .withUserId("VUNGLE_USER_ID")
        .withStartMuted(true)
        .withAutoRotate(AdConfig.LANDSCAPE)
        .build();

MoPubRewardedVideos.loadRewardedVideo(mAdUnitId, vungleMediationConfiguration);
Powered by Creativity Driven by Performance Sign Up Here

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!

Was this article helpful?