Early Access - Integrate MREC Ads for for Android or Amazon v6.10.1

Overview

Starting with Vungle SDK v6.4.11, Vungle supports MREC video ads. MREC is an abbreviation for "medium rectangle" ads. Unlike interstitial ads, MREC ads do not require a fullscreen view. Similar to banner ads, MREC video ads are rectangular ads occupying a location anywhere within the app's layout, typically displayed on the top or bottom of the screen, so that the user can continue to interact with the app while the ad is playing. The container size to render an MREC ad is the industry standard: 300x250.

Step 1. Complete Basic Integration

To integrate MREC ads in your Android or Amazon app, begin by following the instructions in the basic integration article. This article contains supplementary information and assumes you have completed basic integration.

Step 2. Implement Event Listeners

Implement Event Listeners

You can use generic callbacks, by implementing LoadAdCallback for ad load events and PlayAdCallback for ad play events, or use inline callbacks when you invoke loadAd and playAd.

LoadAdCallback

6.5.0 & above Legacy
private final LoadAdCallback vungleLoadAdCallback = new LoadAdCallback() { 
  @Override
  public void onAdLoad(String id) { 
    // Ad has been successfully loaded for the placement
  } 

  @Override 
  public void onError(String id, VungleException exception) { 
    // Ad has failed to load for the placement
  }
};
Overridable Methods Description
onAdLoad(String id) Invoked when the ad has been successfully loaded and be played for the placement
onError(String id) Invoked when an error occurs while attempting to play an ad. You will be able to check error message from getLocalizedMessage of VungleException and use getExceptionCode for debugging.

PlayAdCallback

6.10.1 6.8.x & 6.9.x 6.6.x & 6.7.x Legacy
private final PlayAdCallback vunglePlayAdCallback = new PlayAdCallback() {
  @Override
  public void onAdStart(String id) { 
    // Ad experience started
  }
  
  @Override
  public void onAdViewed(String id) { 
    // Ad has rendered
  }

  @Override
  public void onAdEnd(String id) {
    // Ad experience ended
  }

  @Override
  public void onAdClick(String id) {
    // User clicked on ad
  }

  @Override
  public void onAdLeftApplication(String id) {
    // User has left app during an ad experience
  }
  
  @Override
  public void creativeId(String creativeId) {
   // Vungle creative ID to be displayed
  }

  @Override
  public void onError(String id, VungleException exception) { 
    // Ad failed to play
  }
};
Overridable Methods Description
onAdStart(String id) Invoked when the Vungle SDK has successfully launched the advertisement and an advertisement will begin playing momentarily.
onAdViewed(String id) Invoked when the ad is first rendered on device. Please use this callback to track impressions.
onAdEnd(String id) Invoked when the entire ad experience has been completed, just before the control has been returned back to the hosting app.
onAdClick(String id) Invoked when the user has clicked on a video ad or download button.
onAdLeftApplication(String id) Invoked when the user leaves the app before ad experience is completed, such as opening the Store page for the ad.
creativeId(String creativeId) Invoked immediately after playAd has been issued and prior to onAdStart callback. Vungle creative ID to be shown will be passed to be used for tracking or reporting purpose.
onAdError(String id, VungleException exception) Invoked when an error occurs while attempting to play an ad. You will be able to check error message from getLocalizedMessage of VungleException and use getExceptionCode for debugging.

Step 3. Load, Display, and Close an MREC Ad

v6.10.1 API Change

Starting with v6.10.1, we are incorporating MREC ads into VungleBanner, by using MREC as an ad size, for simpler integration. Integration steps will be identical to integration banner ads and same API will be used with AdConfig.AdSize.VUNGLE_MREC as ad size of BannerAdConfig. VungleNativeAd API remains fuctional to this version but we plan to deprecate it in future so we highly recommend publisher to migrate to VungleBanner when updating Vungle Android SDK to v6.10.1.

Please note that the placement ID that you use for MREC must be configured as a MREC placement from Vungle dashboard and attempting to load with a banner placement ID will result in no fill.

Load an MREC Ad

Loading an MREC ad will use banner API with MREC as an ad size. Banners.loadBanner will be called with an BannerAdConfig object that has been configured with AdConfig.AdSize.VUNGLE_MREC with setAdSize. Similarily, you will use Banners.canPlayAd to check ad availability for the MREC placement.

  • Load a MREC ad by calling the loadBanner method:
    6.10.1 6.9.1 & below
    final BannerAdConfig bannerAdConfig = new BannerAdConfig();
    bannerAdConfig.setAdSize(AdConfig.AdSize.VUNGLE_MREC);
    Banners.loadBanner("MREC_ID", bannerAdConfig, vungleLoadAdCallback);
  • Check for banner ad availability by calling the canPlayAd method:
    6.10.1 6.9.1 & below
    final BannerAdConfig bannerAdConfig = new BannerAdConfig();
    bannerAdConfig.setAdSize(AdConfig.AdSize.VUNGLE_MREC);
    Banners.canPlayAd("MREC_ID", bannerAdConfig.getAdSize());

Display an MREC Ad

The view size is fixed and the container which is used to display the MREC ad must be specified to be 300dp x 250dp which can be placed anywhere on the screen.

Similar to loading a MREC, you need to pass a BannerAdConfig with the ad size configured to MREC by calling setAdSize(AdConfig.AdSize.VUNGLE_MREC) and pass this object when calling Banners.getBanner to obtain a MREC ad object to be displayed.

Finally, call the addView to associate an ad container with the MREC ad. Vungle MREC plays with sound enabled as a default, but you can call setMuted with true to start the video muted.

6.10.1 6.9.1 & below
private FrameLayout mrecContainer = findViewById(...);

BannerAdConfig bannerAdConfig = new BannerAdConfig();
bannerAdConfig.setAdSize(AdConfig.AdSize.VUNGLE_MREC);
bannerAdConfig.setMuted(true);

VungleBanner vungleBanner = Banners.getBanner("MREC_ID", bannerAdConfig, vunglePlayAdCallback);
mrecContainer.addView(vungleBanner);
mrecContainer.setVisibility(View.VISIBLE)

Close a Banner Ad

Because the banner ad view has been added to your container view, it must also be removed, in case the ad view disappears from the screen, the activity or fragment is destroyed, or the parent view container is recycled or destroyed.

vungleBanner.destroyAd();

Attach and Detach the State of an MREC Ad

If the user scrolls to a point where the video ad is no longer visible on the screen, you must pause the video, and resume it when it is again visible. To control the pause and resume states, call setAdVisibility from the VungleNativeAd instance, and set it to true when the video is visible and to false when the video goes off screen. The setAdVisibility is not to be confused with View visibility: this setter informs Vungle SDK whether the MREC ad view is visible or not, and depending on it, the SDK pauses or resumes video playback.

  • Pause an MREC ad:
    vungleBanner.setAdVisibility(false);
  • Resume an MREC ad:
    vungleBanner.setAdVisibility(true);
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?