Integrate MREC Ads

Overview

Vungle MREC is currently in BETA phase. Please contact your account manager directly for access to ensure a successful launch.

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.8.1 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 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.
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

Load an MREC Ad

Loading an MREC ad is the same as loading a fullscreen ad. However, the placement must be configured to support an MREC feed. Please contact your Vungle account manager to enable MREC for a placement.

Display an MREC Ad

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

You can place this RelativeLayout anywhere on the screen. You must then call AdConfig.setAdSize to specify the ad size to be AdConfig.AdSize.VUNGLE_MREC and pass this object when calling Vungle.getNativeAd to get the MREC ad object.

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

private RelativeLayout mrecContainer = findViewById(...);

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

VungleNativeAd vungleNativeAd = Vungle.getNativeAd("MREC_ID", adConfig, vunglePlayAdCallback);
View nativeAdView = vungleNativeAd.renderNativeView();
mrecContainer.addView(nativeAdView);

Close an MREC Ad

Because you have added the MREC ad view to your container view, you must also remove it, in case the ad view disappears from the screen, the activity or fragment is destroyed, or the parent view container is recycled or destroyed. If you try to play another MREC ad without closing the previous ad, you may see unexpected behavior in your app. Therefore, invoke finishDisplayingAd to end the ad experience. We also recommend that you remove the view onAdEnd event.

private VungleNativeAd vungleNativeAd;

// Calling finishDisplayingAd when you want to finish displaying MREC Ad
// will trigger onAdEnd and will tell you when you can remove the child
// MREC view container 
vungleNativeAd.finishDisplayingAd();

// And removing empty ad view from container
@Override 
public void onAdEnd(String id, boolean completed) {
    …
    parentView.removeView(nativeAdView);
    vungleNativeAd = null;
    …
}

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

 

Step 4. Customize MREC Ads (Optional)

You have the option to customize individual ads you play by providing a new adConfig object to playAd. When the AdConfig object is null, the ad plays with the default configuration settings; when it is non-null, its settings override those in the AdConfig setter. The following is an example of how to use AdConfig:

Vungle.playAd(placementReferenceID, adConfig, vunglePlayAdCallback);

The above example uses the adConfig object, which contains customized configuration options. Set the AdConfig object as shown:

object
AdConfig adConfig = new AdConfig();
adConfig.setAdOrientation(AdConfig.AUTO_ROTATE);
adConfig.setMuted(true);
Vungle.playAd(placementReferenceID, adConfig, vunglePlayAdCallback);

The following table lists the available AdConfig options for MREC ads:

Option Description

setMuted

'false' if the video should start with its audio settings matching those of your enclosing application; 'true' if it should start muted regardless

setOrdinal

takes an Integer value of ordinal count to track the number of ads that have been played in same session

Note: You may use the same AdConfig object for multiple ads.

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?