MREC Ads

Loading an MREC

To load an MREC, call CreateMRec(), passing in your ad unit ID and desired adview position:

#if UNITY_IOS
string mrecAdUnitId = "ios_ad_unit_ID"; // Retrieve the ID from your account
#else // UNITY_ANDROID
string mrecAdUnitId = "android_ad_unit_ID"; // Retrieve the ID from your account
#endif

public void InitializeMRecAds()
{
  // MRECs are sized to 300x250 on phones and tablets
  MaxSdk.CreateMRec(mrecAdUnitId, MaxSdkBase.AdViewPosition.Centered);

  MaxSdkCallbacks.MRec.OnAdLoadedEvent      += OnMRecAdLoadedEvent;
  MaxSdkCallbacks.MRec.OnAdLoadFailedEvent  += OnMRecAdLoadFailedEvent;
  MaxSdkCallbacks.MRec.OnAdClickedEvent     += OnMRecAdClickedEvent;
  MaxSdkCallbacks.MRec.OnAdRevenuePaidEvent += OnMRecAdRevenuePaidEvent;
  MaxSdkCallbacks.MRec.OnAdExpandedEvent    += OnMRecAdExpandedEvent;
  MaxSdkCallbacks.MRec.OnAdCollapsedEvent   += OnMRecAdCollapsedEvent;
}

public void OnMRecAdLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

public void OnMRecAdLoadFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo error) {}

public void OnMRecAdClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

public void OnMRecAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

public void OnMRecAdExpandedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

public void OnMRecAdCollapsedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

The above example creates an MREC centered on the display (Centered). The complete list of position options are:

  • TopLeft
  • TopCenter
  • TopRight
  • Centered
  • CenterLeft
  • CenterRight
  • BottomLeft
  • BottomCenter
  • BottomRight

You can also position an MREC at a specific (x, y) coordinate on the screen by calling MaxSdk.CreateMRec(ad-unit-ID, x, y);. This sets the position of the top-left corner of the ad. The coordinate system represents the safe area bounds of the screen. Make sure to account for the width and height of the ad when you set these coordinates. The position (0, 0) is equivalent to TopLeft; the bottom-right corner of the safe area is (safeAreaWidth, safeAreaHeight). Note that Unity might have a different screen size or safe area size than Android or iOS. To convert between Unity’s screen size and the sizes used in Android or iOS, use code like the following:

var density = MaxSdkUtils.GetScreenDensity();
var dp = pixels / density;

Hiding and Showing an MREC

To show an MREC ad, call ShowMRec():

MaxSdk.ShowMRec(mrecAdUnitId);

To hide an MREC ad, call HideMRec():

MaxSdk.HideMRec(mrecAdUnitId);

Destroying MREC Ads

After you are no longer using an MREC instance (for example, if the user purchased ad removal), call the DestroyMRec() method to free resources. Do not call DestroyMRec() if you use multiple MREC instances with the same Ad Unit ID.

MaxSdk.DestroyMRec(ad_unit_ID);

Stopping and Starting Auto-Refresh

There may be cases when you would like to stop auto-refresh, for instance, if you want to manually refresh MREC ads. To stop auto-refresh for an MREC ad, use the following code:

MaxSdk.StopMRecAutoRefresh(ad_unit_ID);

Start auto-refresh for an MREC ad with the following code:

MaxSdk.StartMRecAutoRefresh(ad_unit_ID);

Manually refresh the contents with the following code. Note that you must stop auto-refresh before you call LoadMRec().

MaxSdk.LoadMRec(ad_unit_ID);