Banner & MREC Ads

Integrate CloudX banner and MREC ads in Unity games

Standard banner ads displayed at a fixed screen position with auto-refresh functionality.

using CloudX;
using UnityEngine;

public class BannerExample : MonoBehaviour
{
    private const string BannerAdUnitId = "banner_main";

    void Start()
    {
        // Subscribe to callbacks
        CloudXAdsCallbacks.Banner.OnAdLoadSuccess += OnBannerLoaded;
        CloudXAdsCallbacks.Banner.OnAdLoadFailed += OnBannerLoadFailed;
        CloudXAdsCallbacks.Banner.OnAdClicked += OnBannerClicked;
        CloudXAdsCallbacks.Banner.OnAdRevenuePaid += OnBannerRevenuePaid;

        // Create, load, and show banner
        var config = new CloudXAdViewConfiguration(CloudXAdViewConfiguration.AdViewPosition.BottomCenter);
        CloudXSdk.CreateBanner(BannerAdUnitId, config);
        CloudXSdk.LoadBanner(BannerAdUnitId);
        CloudXSdk.ShowBanner(BannerAdUnitId);
    }

    void OnApplicationFocus(bool hasFocus)
    {
        if (hasFocus)
        {
            CloudXSdk.ShowBanner(BannerAdUnitId);
        }
        else
        {
            CloudXSdk.HideBanner(BannerAdUnitId);
        }
    }

    private void OnBannerLoaded(CloudXAd ad)
    {
        Debug.Log($"Banner loaded: {ad.AdUnitId}");
    }

    private void OnBannerLoadFailed(string adUnitId, CloudXError error)
    {
        Debug.LogError($"Banner failed to load: {adUnitId} - {error}");
    }

    private void OnBannerClicked(CloudXAd ad)
    {
        Debug.Log($"Banner clicked: {ad.AdUnitId}");
    }

    private void OnBannerRevenuePaid(CloudXAd ad)
    {
        Debug.Log($"Banner revenue: ${ad.Revenue} from {ad.NetworkName}");
    }
}

Auto-Refresh Control

Banner ads auto-refresh by default. To control refresh manually:

CloudXSdk.StopBannerAutoRefresh(BannerAdUnitId);  // Stop auto-refresh
CloudXSdk.LoadBanner(BannerAdUnitId);              // Manually load
CloudXSdk.StartBannerAutoRefresh(BannerAdUnitId); // Re-enable auto-refresh

Placement and Custom Data

CloudXSdk.SetBannerPlacement(BannerAdUnitId, "home_screen");
CloudXSdk.SetBannerCustomData(BannerAdUnitId, "custom_value");

Vertical Banner Ads (320x50, rotated)

A vertical banner is a standard 320x50 banner rotated 90 degrees and pinned flush against the left or right screen edge. It is vertically centered on that edge, and the top of the creative faces the screen center. When a display cutout (notch, camera hole, Dynamic Island) occupies that edge, which is common in landscape, the banner is automatically inset past it so the creative is never obscured.

This format is particularly well suited for landscape games that don’t have the vertical space for a top or bottom banner: instead of eating into the gameplay area’s height, the banner uses the short screen edges.

To create a vertical banner, construct the CloudXAdViewConfiguration with an AdViewVerticalPosition instead of an AdViewPosition. Loading, showing, callbacks (CloudXAdsCallbacks.Banner), auto-refresh control, and placement/custom data work similarly to horizontal banners.

// Pin the banner flush against the left screen edge (rotated clockwise)
var config = new CloudXAdViewConfiguration(
    CloudXAdViewConfiguration.AdViewVerticalPosition.Left);
CloudXSdk.CreateBanner(BannerAdUnitId, config);
CloudXSdk.LoadBanner(BannerAdUnitId);
CloudXSdk.ShowBanner(BannerAdUnitId);

AdViewVerticalPosition.Left pins the banner flush against the left screen edge, rotated clockwise; AdViewVerticalPosition.Right pins it against the right screen edge, rotated counter-clockwise.

MREC Ads (300x250)

Medium Rectangle ads work the same way as banners but with a larger size.

using CloudX;
using UnityEngine;

public class MrecExample : MonoBehaviour
{
    private const string MrecAdUnitId = "mrec_main";

    void Start()
    {
        // Subscribe to callbacks
        CloudXAdsCallbacks.Mrec.OnAdLoadSuccess += OnMrecLoaded;
        CloudXAdsCallbacks.Mrec.OnAdLoadFailed += OnMrecLoadFailed;
        CloudXAdsCallbacks.Mrec.OnAdClicked += OnMrecClicked;
        CloudXAdsCallbacks.Mrec.OnAdRevenuePaid += OnMrecRevenuePaid;

        // Create, load, and show MREC
        var config = new CloudXAdViewConfiguration(CloudXAdViewConfiguration.AdViewPosition.Centered);
        CloudXSdk.CreateMrec(MrecAdUnitId, config);
        CloudXSdk.LoadMrec(MrecAdUnitId);
        CloudXSdk.ShowMrec(MrecAdUnitId);
    }

    void OnApplicationFocus(bool hasFocus)
    {
        if (hasFocus)
        {
            CloudXSdk.ShowMrec(MrecAdUnitId);
        }
        else
        {
            CloudXSdk.HideMrec(MrecAdUnitId);
        }
    }

    private void OnMrecLoaded(CloudXAd ad)
    {
        Debug.Log($"MREC loaded: {ad.AdUnitId}");
    }

    private void OnMrecLoadFailed(string adUnitId, CloudXError error)
    {
        Debug.LogError($"MREC failed to load: {adUnitId} - {error}");
    }

    private void OnMrecClicked(CloudXAd ad)
    {
        Debug.Log($"MREC clicked: {ad.AdUnitId}");
    }

    private void OnMrecRevenuePaid(CloudXAd ad)
    {
        Debug.Log($"MREC revenue: ${ad.Revenue} from {ad.NetworkName}");
    }
}

Placement and Custom Data

CloudXSdk.SetMRecPlacement(MrecAdUnitId, "home_screen");
CloudXSdk.SetMRecCustomData(MrecAdUnitId, "custom_value");

Auto-Refresh Control

MREC ads also auto-refresh by default. Use the same refresh control methods as banners:

CloudXSdk.StopMrecAutoRefresh(MrecAdUnitId);
CloudXSdk.LoadMrec(MrecAdUnitId);
CloudXSdk.StartMrecAutoRefresh(MrecAdUnitId);