Integrating MoPub + Vungle SDK v.5 (Android)

Use this guide to add Vungle Android SDK into your app, using MoPub as your main advertising mediation layer.

Contents

Before You Begin

Step 1. Set Up Vungle as a Custom Native Network

To ensure that the MoPub servers recognize the integrated Vungle Adapters, set up Vungle as a Custom Native Network in the MoPub dashboard. 

  1. Log into the MoPub dashboard, and select Networks​ from the main navigation bar.

  2. Click Add a Network​….

    image4.png

    and select Custom Native Network​ at the bottom of the page.

    image1.png
  1. In the Set Up Your Inventory section, for each ad unit that will use the Vungle SDK to present video ads, ensure that the MoPub SDK can find the network adapter used to interact with the Vungle SDK:

    image2.png

    • If you are using MoPub Rewarded Video​ for an Ad Unit, add com.mopub.mobileads.VungleRewardedVideo under the Custom Event Class​ section.

    • If you are using Fullscreen (Interstitial)​ for an Ad Unit, add com.mopub.mobileads.VungleInterstitial under the Custom Event Class​ section.

    • Add your Vungle App ID​, placement Reference ID​, and all placement Reference IDs​ in JSON format under the Custom Event Class Data​.

    • Set the placement Reference ID you want to link to the MoPub Ad Unit for pid​.
      Note: A default placement is created for each app automatically. You must provide its placement reference ID in this initialization step whether or not you plan to take advantage of the placements functionality. If you create multiple placements, provide all the reference IDs.

    • Make sure to link the placement Reference ID set to “Rewarded” to the MoPub Ad Unit that is set to Rewarded Video​; and link the placement Reference ID that is NOT set to “Rewarded” to the MoPub Ad Unit that is set to Fullscreen (Interstitial)​.
      {
      "appId":"5935efecc802d63d5100000f",
      "pid":"DEFAULT05223",
      "pids":"DEFAULT05223, PADUNIT49379, PADUNIT68848, PADUNIT04241, PADUNIT53279, PADUNIT08448"
      }

Note:​ The Vungle SDK will cache an ad automatically for the placement you selected to be Auto Cached​ in the Vungle Dashboard. We highly recommend selecting the MoPub Ad Unit shown first or the Ad Unit shown most frequently as the Auto Cached​ placement.

Step 2. Add Vungle as a Third-Party Ad Network

To add the Vungle Android SDK into your app using MoPub mediation:

  1. Add all the Vungle-related adapter files (under /extras/src/com/mopub/mobileads/ in the MoPub Adapter Repository) to the /src/main/java/com/mopub/mobileads/ directory in your app’s project. This step is necessary because the MoPub SDK references these files as “Custom Event Class properties” in the directory.

    • VungleInterstitial.java
    • VungleRewardedVideo.java
    • VungleRouter.java
    • VungleRouterListener.java

  2. Follow the instructions in the “Step 1. Include the Vungle SDK in Your Project“ section of “Get Started with Vungle - Android SDK“ to add the necessary frameworks.

  3. If you need to set Multidex , Proguard and Google Play Services, follow the instructions in the “Advanced Settings“ section of “Get Started with Vungle - Android SDK“ to update AndroidManifest.xml in your project.

  4. Call the MoPubInterstitial’s show method (or, for rewarded ads, call the MoPubRewardedVideos's showRewardedVideo method) when you want to present a Vungle video ad. (No need to call the Vungle Android SDK methods directly. The MoPub SDK will do it.)

Configuration Options (Optional)

Interstitial Ads

Attribute

Default Value

Description

SOUND_ENABLED_KEY

true

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

ORDINAL_VIEW_COUNT_KEY

null

If you receive ordinal data reports from Vungle, use this field to pass the mediation ordinal. This is an integer indicating the order in which this ad was shown in the game session (for example, if two ads were already shown in this session, and this ad from Vungle was then shown third, pass in '3'). Read more about ordinal data here.

FLEX_VIEW_CLOSE_TIME_KEY

null

This the the amount of seconds the flex view videos will play before they automatically close.

Example

private Map<String, Object> getLocalExtras() {
   HashMap<String, Object> extras = new HashMap<>();
   extras.put(VungleInterstitial.SOUND_ENABLED_KEY,
           mPreferences.getBoolean(SettingsActivity.KEY_PREF_SOUND_ENABLED, true));
   extras.put(VungleInterstitial.ORDINAL_VIEW_COUNT_KEY,
           Util.parseInt(mPreferences.getString(SettingsActivity.KEY_PREF_PREF_KEY_ORDINAL, "3"), 0));
   return extras;

Rewarded Ads

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.

withCancelDialogBody

"Closing this video early will prevent you from earning your reward. Are you sure?"

Sets the body of the confirmation dialog when skipping an incentivized ad.

withCancelDialogCloseButton

“Close Video”

Sets the 'cancel button' text of the confirmation dialog when skipping an incentivized ad.

withCancelDialogKeepWatchingButton

“Keep Watching”

Sets the 'keep watching button' text of the confirmation dialog when skipping an incentivized ad.

withCancelDialogTitle

“Close Video?”

Sets the title of the confirmation dialog when skipping an incentivized ad.

withSoundEnabled

true

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

withOrdinalViewCount

null

If you receive ordinal data reports from Vungle, use this field to pass the mediation ordinal. This is an integer indicating the order in which this ad was shown in the game session (for example, if two ads were already shown in this session, and this ad from Vungle was then shown third, pass in '3'). Read more about ordinal data here.

withFlexViewCloseTimeInSec

null

This the the amount of seconds the flex view videos will play before they automatically close.

Example

private VungleMediationSettings getSettings() {
   return new VungleMediationSettings.Builder()
           .withUserId(mPreferences.getString(SettingsActivity.KEY_PREF_USER_ID, "user"))
           .withCancelDialogBody(mPreferences.getString(SettingsActivity.KEY_PREF_CANCEL_BODY, ""))
           .withCancelDialogCloseButton(mPreferences.getString(SettingsActivity.KEY_PREF_CANCEL_CLOSE, ""))
.withFlexViewCloseTimeInSec(Util.parseInt(mPreferences.getString(SettingsActivity.KEY_PREF_PREF_KEY_FLEXVIEW_CLOSE_TIME, "5"), 0))
.withCancelDialogKeepWatchingButton(mPreferences.getString(SettingsActivity.KEY_PREF_CANCEL_KEEP, ""))
           .withCancelDialogTitle(mPreferences.getString(SettingsActivity.KEY_PREF_CANCEL_TITLE, ""))
           .withSoundEnabled(mPreferences.getBoolean(SettingsActivity.KEY_PREF_SOUND_ENABLED, true))
.withOrdinalViewCount(Util.parseInt(mPreferences.getString(SettingsActivity.KEY_PREF_PREF_KEY_ORDINAL, "13"), 0))
           .build();
}
Have more questions? Submit a request

Comments