CloudX Unity SDK
The CloudX Unity SDK enables monetization of your Unity games with banner, MREC, interstitial, and rewarded ads across iOS and Android.
Installation
The CloudX Unity SDK is distributed as a .unitypackage file.
- Download the latest
CloudX-Unity-SDK.unitypackage from GitHub Releases
- In Unity, go to Assets > Import Package > Custom Package
- Select the downloaded
.unitypackage file
- Import all assets when prompted
The External Dependency Manager will automatically resolve Android and iOS dependencies.
Ad Network Adapters
The CloudX SDK requires ad network adapters to serve ads. Adapters are optional and can be enabled based on which ad networks you want to support.
Enabling Adapters
Open Assets/CloudXSdk/Editor/CloudXDependencies.xml and uncomment the adapters you need:
<?xml version="1.0" encoding="utf-8"?>
<dependencies>
<androidPackages>
<!-- CloudX Core SDK -->
<androidPackage spec="io.cloudx:sdk:0.12.0"/>
<!-- Optional: CloudX Adapters (uncomment as needed) -->
<androidPackage spec="io.cloudx:adapter-cloudx:0.12.0"/>
<androidPackage spec="io.cloudx:adapter-meta:0.12.0"/>
<androidPackage spec="io.cloudx:adapter-vungle:0.12.0"/>
</androidPackages>
</dependencies>
After modifying the file, go to Assets > External Dependency Manager > Android Resolver > Force Resolve to download the new dependencies.
Available Adapters
| Adapter | Package | Description |
|---|
| CloudX Network | io.cloudx:adapter-cloudx | CloudX ad network |
| Meta Audience Network | io.cloudx:adapter-meta | Facebook/Meta ads |
| Vungle | io.cloudx:adapter-vungle | Vungle video ads |
At least one adapter is required for the SDK to serve ads.
Initialization
Initialize the SDK before loading any ads. You can optionally configure user and app properties before initialization.
using CloudX;
using UnityEngine;
public class MyGameManager : MonoBehaviour
{
void Start()
{
InitializeCloudX();
}
async void InitializeCloudX()
{
// Pre-initialization configuration (optional)
CloudXSdk.SetHashedUserId("hashed-user-id");
CloudXSdk.SetUserKeyValue("user_level", "premium");
CloudXSdk.SetAppKeyValue("app_version", "1.0.0");
// Initialize SDK
var error = await CloudXSdk.InitializeAsync("YOUR_APP_KEY", testMode: true);
if (error != null)
{
Debug.LogError($"SDK initialization failed: {error}");
return;
}
Debug.Log("CloudX SDK initialized successfully");
// Now you can load ads
}
}
InitializeAsync returns null on success, or a CloudXError object on failure.
Ad Integration
Banner Ads
Standard banner ads with auto-refresh functionality.
using CloudX;
using UnityEngine;
public class BannerExample : MonoBehaviour
{
private const string BannerPlacement = "banner_main";
void Start()
{
// Subscribe to callbacks
CloudXAdsCallbacks.Banner.OnAdLoadSuccess += OnBannerLoaded;
CloudXAdsCallbacks.Banner.OnAdLoadFailed += OnBannerLoadFailed;
CloudXAdsCallbacks.Banner.OnAdClicked += OnBannerClicked;
CloudXAdsCallbacks.Banner.OnAdRevenuePaid += OnBannerRevenuePaid;
// Create and show banner
var config = new CloudXAdViewConfiguration(CloudXAdViewConfiguration.AdViewPosition.BottomCenter);
CloudXSdk.CreateBanner(BannerPlacement, config);
CloudXSdk.ShowBanner(BannerPlacement);
}
void OnApplicationFocus(bool hasFocus)
{
if (hasFocus)
{
CloudXSdk.ShowBanner(BannerPlacement);
}
else
{
CloudXSdk.HideBanner(BannerPlacement);
}
}
private void OnBannerLoaded(CloudXAd ad)
{
Debug.Log($"Banner loaded: {ad.PlacementName}");
}
private void OnBannerLoadFailed(CloudXError error)
{
Debug.LogError($"Banner failed to load: {error}");
}
private void OnBannerClicked(CloudXAd ad)
{
Debug.Log($"Banner clicked: {ad.PlacementName}");
}
private void OnBannerRevenuePaid(CloudXAd ad)
{
Debug.Log($"Banner revenue: ${ad.Revenue} from {ad.BidderName}");
}
}
Auto-Refresh Control:
Banner ads auto-refresh by default. To control refresh manually:
CloudXSdk.StopBannerAutoRefresh(BannerPlacement); // Stop auto-refresh
CloudXSdk.LoadBanner(BannerPlacement); // Manually load
CloudXSdk.StartBannerAutoRefresh(BannerPlacement); // Re-enable auto-refresh
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 MrecPlacement = "mrec_main";
void Start()
{
// Subscribe to callbacks
CloudXAdsCallbacks.Mrec.OnAdLoadSuccess += OnMrecLoaded;
CloudXAdsCallbacks.Mrec.OnAdLoadFailed += OnMrecLoadFailed;
CloudXAdsCallbacks.Mrec.OnAdClicked += OnMrecClicked;
CloudXAdsCallbacks.Mrec.OnAdRevenuePaid += OnMrecRevenuePaid;
// Create and show MREC
var config = new CloudXAdViewConfiguration(CloudXAdViewConfiguration.AdViewPosition.Centered);
CloudXSdk.CreateMrec(MrecPlacement, config);
CloudXSdk.ShowMrec(MrecPlacement);
}
void OnApplicationFocus(bool hasFocus)
{
if (hasFocus)
{
CloudXSdk.ShowMrec(MrecPlacement);
}
else
{
CloudXSdk.HideMrec(MrecPlacement);
}
}
private void OnMrecLoaded(CloudXAd ad)
{
Debug.Log($"MREC loaded: {ad.PlacementName}");
}
private void OnMrecLoadFailed(CloudXError error)
{
Debug.LogError($"MREC failed to load: {error}");
}
private void OnMrecClicked(CloudXAd ad)
{
Debug.Log($"MREC clicked: {ad.PlacementName}");
}
private void OnMrecRevenuePaid(CloudXAd ad)
{
Debug.Log($"MREC revenue: ${ad.Revenue} from {ad.BidderName}");
}
}
Auto-Refresh Control:
MREC ads also auto-refresh by default. Use the same refresh control methods as banners:
CloudXSdk.StopMrecAutoRefresh(MrecPlacement);
CloudXSdk.LoadMrec(MrecPlacement);
CloudXSdk.StartMrecAutoRefresh(MrecPlacement);
Interstitial Ads
Full-screen ads that are shown between content transitions.
using CloudX;
using UnityEngine;
public class InterstitialExample : MonoBehaviour
{
private const string InterstitialPlacement = "interstitial_main";
void Start()
{
// Subscribe to callbacks
CloudXAdsCallbacks.Interstitial.OnAdLoadSuccess += OnInterstitialLoaded;
CloudXAdsCallbacks.Interstitial.OnAdLoadFailed += OnInterstitialLoadFailed;
CloudXAdsCallbacks.Interstitial.OnAdShowSuccess += OnInterstitialShown;
CloudXAdsCallbacks.Interstitial.OnAdShowFailed += OnInterstitialShowFailed;
CloudXAdsCallbacks.Interstitial.OnAdHidden += OnInterstitialHidden;
CloudXAdsCallbacks.Interstitial.OnAdClicked += OnInterstitialClicked;
CloudXAdsCallbacks.Interstitial.OnAdRevenuePaid += OnInterstitialRevenuePaid;
// Load interstitial
CloudXSdk.LoadInterstitial(InterstitialPlacement);
}
public void ShowInterstitial()
{
if (CloudXSdk.IsInterstitialReady(InterstitialPlacement))
{
CloudXSdk.ShowInterstitial(InterstitialPlacement);
}
else
{
Debug.LogWarning("Interstitial not ready yet");
}
}
private void OnInterstitialLoaded(CloudXAd ad)
{
Debug.Log($"Interstitial loaded: {ad.PlacementName}");
}
private void OnInterstitialLoadFailed(CloudXError error)
{
Debug.LogError($"Interstitial failed to load: {error}");
}
private void OnInterstitialShown(CloudXAd ad)
{
Debug.Log($"Interstitial shown: {ad.PlacementName}");
}
private void OnInterstitialShowFailed(CloudXError error)
{
Debug.LogError($"Interstitial failed to show: {error}");
}
private void OnInterstitialHidden(CloudXAd ad)
{
Debug.Log($"Interstitial hidden: {ad.PlacementName}");
// Reload for next time
CloudXSdk.LoadInterstitial(InterstitialPlacement);
}
private void OnInterstitialClicked(CloudXAd ad)
{
Debug.Log($"Interstitial clicked: {ad.PlacementName}");
}
private void OnInterstitialRevenuePaid(CloudXAd ad)
{
Debug.Log($"Interstitial revenue: ${ad.Revenue} from {ad.BidderName}");
}
}
Rewarded Ads
Reward users for watching video ads.
using CloudX;
using UnityEngine;
public class RewardedExample : MonoBehaviour
{
private const string RewardedPlacement = "rewarded_main";
void Start()
{
// Subscribe to callbacks
CloudXAdsCallbacks.Rewarded.OnAdLoadSuccess += OnRewardedLoaded;
CloudXAdsCallbacks.Rewarded.OnAdLoadFailed += OnRewardedLoadFailed;
CloudXAdsCallbacks.Rewarded.OnAdShowSuccess += OnRewardedShown;
CloudXAdsCallbacks.Rewarded.OnAdShowFailed += OnRewardedShowFailed;
CloudXAdsCallbacks.Rewarded.OnAdHidden += OnRewardedHidden;
CloudXAdsCallbacks.Rewarded.OnAdClicked += OnRewardedClicked;
CloudXAdsCallbacks.Rewarded.OnAdRewarded += OnUserRewarded;
CloudXAdsCallbacks.Rewarded.OnAdRevenuePaid += OnRewardedRevenuePaid;
// Load rewarded ad
CloudXSdk.LoadRewarded(RewardedPlacement);
}
public void ShowRewardedAd()
{
if (CloudXSdk.IsRewardedReady(RewardedPlacement))
{
CloudXSdk.ShowRewarded(RewardedPlacement);
}
else
{
Debug.LogWarning("Rewarded ad not ready yet");
}
}
private void OnRewardedLoaded(CloudXAd ad)
{
Debug.Log($"Rewarded ad loaded: {ad.PlacementName}");
}
private void OnRewardedLoadFailed(CloudXError error)
{
Debug.LogError($"Rewarded ad failed to load: {error}");
}
private void OnRewardedShown(CloudXAd ad)
{
Debug.Log($"Rewarded ad shown: {ad.PlacementName}");
}
private void OnRewardedShowFailed(CloudXError error)
{
Debug.LogError($"Rewarded ad failed to show: {error}");
}
private void OnRewardedHidden(CloudXAd ad)
{
Debug.Log($"Rewarded ad hidden: {ad.PlacementName}");
// Reload for next time
CloudXSdk.LoadRewarded(RewardedPlacement);
}
private void OnRewardedClicked(CloudXAd ad)
{
Debug.Log($"Rewarded ad clicked: {ad.PlacementName}");
}
private void OnUserRewarded(CloudXAd ad)
{
Debug.Log($"User earned reward from: {ad.PlacementName}");
// Grant reward to user here
GrantRewardToUser();
}
private void OnRewardedRevenuePaid(CloudXAd ad)
{
Debug.Log($"Rewarded ad revenue: ${ad.Revenue} from {ad.BidderName}");
}
private void GrantRewardToUser()
{
// Your reward logic here
Debug.Log("Granting reward to user!");
}
}
Advanced Features
User Targeting
Configure user and app properties for better ad targeting. Call these methods before InitializeAsync.
// Set hashed user ID
CloudXSdk.SetHashedUserId("hashed-user-id-12345");
// Set user-level key-value pairs
CloudXSdk.SetUserKeyValue("user_level", "premium");
CloudXSdk.SetUserKeyValue("age_group", "25-34");
// Set app-level key-value pairs
CloudXSdk.SetAppKeyValue("app_version", "1.0.0");
CloudXSdk.SetAppKeyValue("build_number", "123");
// Clear all custom key-values
CloudXSdk.ClearAllKeyValues();
Revenue Tracking
All ad formats provide revenue callbacks through the OnAdRevenuePaid event. The CloudXAd object contains revenue information:
CloudXAdsCallbacks.Banner.OnAdRevenuePaid += (ad) =>
{
Debug.Log($"Revenue: ${ad.Revenue:F4}");
Debug.Log($"Bidder: {ad.BidderName}");
Debug.Log($"Placement: {ad.PlacementName}");
// Track revenue in your analytics
TrackRevenue(ad.Revenue, ad.BidderName);
};