Migrate from Unity Ads to LevelPlay
Migrate from direct integration of the Unity Ads SDK using the Advertisement Legacy package to LevelPlay integration with the Ads Mediation package.
阅读时间6 分钟最后更新于 1 天前
This guide explains how to transition your project from direct Unity Ads SDK integration to LevelPlay SDK integration, including API mapping for common use cases. For more details, refer to the LevelPlay integration guide. Refer to the following table for the main steps for migrating to LevelPlay:
Topic | Description |
|---|---|
| Migrate to Ads Mediation | Transition your project from legacy Unity Ads to LevelPlay. |
| Map APIs and update code | Replace legacy initialization, banner, interstitial, and rewarded ad calls with their LevelPlay equivalents. |
| Testing and verification | Optionally, validate your new integration using the LevelPlay Test Suite and the built-in integration validation tools. |
| API and feature mapping reference | Review how the legacy Unity Ads functions and parameters map to the corresponding LevelPlay alternatives. |
| Remove the legacy package | Uninstall the Advertisement Legacy package and resolve any remaining dependencies in your project. |
Prerequisites
Make sure you have access to the LevelPlay dashboard.Migrate to Ads Mediation
To replace the legacy Unity Ads integration with LevelPlay, follow these steps:Install the LevelPlay package
To install the LevelPlay package using the Unity Package Manager, follow these steps:- In the Unity Editor, go to Window > Package Manager.
- Select Packages: Unity Registry.
- Search for Ads Mediation.
- Select Install for the latest version.
Configure dependencies
LevelPlay requires a dependency resolver like the Mobile Dependency Resolver or External Dependency Manager for Unity (EDM4U) to manage Android and iOS libraries. Verify that a dependency resolver is installed in your project. If your project already contains a dependency resolver, keep it. If a prompt appears asking to install Mobile Dependency Resolver after the LevelPlay installation, select Yes.Configure the LevelPlay dashboard
Configure the LevelPlay dashboard to register your app and create the ad units required for mediation.- Log in to the LevelPlay dashboard.
- Select Add App and follow the prompts to register your application.
- Navigate to Ad Units and select the app to manage.
- Create the desired ad units (Banner, Interstitial, or Rewarded). For more information about ad units, refer to the Manage ad units documentation.
- In the LevelPlay dashboard Apps page, locate and save your App Key and Ad Unit IDs; you need these to Map APIs.
Map APIs and update code
Replace your existingAdvertisementLevelPlayInitialize the LevelPlay SDK
The LevelPlay SDK uses an App Key instead of a Game ID. To register event listeners and initialize the SDK, refer to the following sample:LevelPlay.OnInitSuccess += SdkInitializationCompletedEvent;LevelPlay.OnInitFailed += SdkInitializationFailedEvent;LevelPlay.Init("YOUR_APPKEY");void SdkInitializationCompletedEvent(LevelPlayConfiguration config){ Debug.Log($"[LevelPlaySample] Received SdkInitializationCompletedEvent with Config: {config}");}void SdkInitializationFailedEvent(LevelPlayInitError error){ Debug.Log($"[LevelPlaySample] Received SdkInitializationFailedEvent with Error: {error}"); }
Implement Banner Ads
To implement Banner ads, refer to the following sample:public class BannerAdSample { private LevelPlayBannerAd bannerAd; void CreateBannerAd() { // Create ad configuration - optional var adConfig = new LevelPlayBannerAd.Config.Builder() .SetSize(LevelPlayAdSize.BANNER) .SetPlacementName("placementName") .SetPosition(LevelPlayBannerPosition.BottomCenter) .SetDisplayOnLoad(true) .SetRespectSafeArea(true) .Build(); // Create banner instance bannerAd = new LevelPlayBannerAd("YOUR_BANNER_AD_UNIT_ID", adConfig); // Subscribe BannerAd events bannerAd.OnAdLoaded += BannerOnAdLoadedEvent; bannerAd.OnAdLoadFailed += BannerOnAdLoadFailedEvent; bannerAd.OnAdDisplayed += BannerOnAdDisplayedEvent; bannerAd.OnAdDisplayFailed += BannerOnAdDisplayFailedEvent; bannerAd.OnAdClicked += BannerOnAdClickedEvent; bannerAd.OnAdCollapsed += BannerOnAdCollapsedEvent; bannerAd.OnAdLeftApplication += BannerOnAdLeftApplicationEvent; bannerAd.OnAdExpanded += BannerOnAdExpandedEvent; } public void LoadBannerAd() { //Load the banner ad bannerAd.LoadAd(); } public void ShowBannerAd() { //Show the banner ad, call this method only if you turned off the auto show when you created this banner instance. bannerAd.ShowAd(); } public void HideBannerAd() { //Hide banner bannerAd.HideAd(); } public void DestroyBannerAd() { //Destroy banner bannerAd.DestroyAd(); } //Implement BannerAd Events public void BannerOnAdLoadedEvent(LevelPlayAdInfo adInfo) {} public void BannerOnAdLoadFailedEvent(LevelPlayAdError ironSourceError) {} public void BannerOnAdClickedEvent(LevelPlayAdInfo adInfo) {} public void BannerOnAdDisplayedEvent(LevelPlayAdInfo adInfo) {} public void BannerOnAdDisplayFailedEvent(LevelPlayAdInfo adInfo, LevelPlayAdError error){} public void BannerOnAdCollapsedEvent(LevelPlayAdInfo adInfo) {} public void BannerOnAdLeftApplicationEvent(LevelPlayAdInfo adInfo) {} public void BannerOnAdExpandedEvent(LevelPlayAdInfo adInfo) {}}
Implement Interstitial Ads
To implement interstitial ads, refer to the following sample:public class InterstitialAdSample { private LevelPlayInterstitialAd interstitialAd; void CreateInterstitialAd() { // Create InterstitialAd instance interstitialAd = new LevelPlayInterstitialAd("YOUR_INTERSTITIAL_AD_UNIT_ID"); // Subscribe InterstitialAd events interstitialAd.OnAdLoaded += InterstitialOnAdLoadedEvent; interstitialAd.OnAdLoadFailed += InterstitialOnAdLoadFailedEvent; interstitialAd.OnAdDisplayed += InterstitialOnAdDisplayedEvent; interstitialAd.OnAdDisplayFailed += InterstitialOnAdDisplayFailedEvent; interstitialAd.OnAdClicked += InterstitialOnAdClickedEvent; interstitialAd.OnAdClosed += InterstitialOnAdClosedEvent; interstitialAd.OnAdInfoChanged += InterstitialOnAdInfoChangedEvent; } void LoadInterstitialAd() { // Load or reload InterstitialAd interstitialAd.LoadAd(); } void ShowInterstitialAd() { // Show InterstitialAd, check if the ad is ready before showing if (interstitialAd.IsAdReady()) { interstitialAd.ShowAd(); } } void DestroyInterstitialAd() { // Destroy InterstitialAd interstitialAd.DestroyAd(); } // Implement InterstitialAd events void InterstitialOnAdLoadedEvent(LevelPlayAdInfo adInfo) { } void InterstitialOnAdLoadFailedEvent(LevelPlayAdError error) { } void InterstitialOnAdClickedEvent(LevelPlayAdInfo adInfo) { } void InterstitialOnAdDisplayedEvent(LevelPlayAdInfo adInfo) { } void InterstitialOnAdDisplayFailedEvent(LevelPlayAdInfo adInfo, LevelPlayAdError error) { } void InterstitialOnAdClosedEvent(LevelPlayAdInfo adInfo) { } void InterstitialOnAdInfoChangedEvent(LevelPlayAdInfo adInfo) { }}
Rewarded Ads
To implement rewarded ads, refer to the following sample:public class LevelPlaySample : MonoBehaviour{ private LevelPlayRewardedAd rewardedAd; void CreateRewardedAd() { rewardedAd = new LevelPlayRewardedAd("YOUR_REWARDED_AD_UNIT_ID"); rewardedAd.OnAdLoaded += OnAdLoaded; rewardedAd.OnAdLoadFailed += OnAdLoadFailed; rewardedAd.OnAdDisplayed += OnAdDisplayed; rewardedAd.OnAdDisplayFailed += OnAdDisplayFailed; rewardedAd.OnAdRewarded += OnAdRewarded; rewardedAd.OnAdClicked += OnAdClicked; rewardedAd.OnAdClosed += OnAdClosed; rewardedAd.OnAdInfoChanged += OnAdInfoChanged; } void LoadRewardedAd() { rewardedAd.LoadAd(); } void ShowRewardedAd(string placementName = null) { if (rewardedAd.IsAdReady() && !LevelPlayRewardedAd.IsPlacementCapped(placementName)) { rewardedAd.ShowAd(placementName); } } bool CheckIfRewardedAdIsReady() { return rewardedAd.IsAdReady(); } bool CheckIfPlacementIsCapped(string placementName) { return LevelPlayRewardedAd.IsPlacementCapped(placementName); } void OnAdLoaded(LevelPlayAdInfo adInfo) { Debug.Log($"Rewarded ad loaded with ad info {adInfo}"); } void OnAdLoadFailed(LevelPlayAdError adError) { Debug.Log($"Rewarded ad failed to load with ad error {adError}"); } void OnAdDisplayed(LevelPlayAdInfo adInfo) { Debug.Log($"Rewarded ad displayed with ad info {adInfo}"); } void OnAdDisplayFailed(LevelPlayAdDisplayInfoError adInfoError) { Debug.Log($"Rewarded ad failed to display with ad info and error {adInfoError}"); } void OnAdRewarded(LevelPlayAdInfo adInfo, LevelPlayReward adReward) { Debug.Log($"Rewarded ad gained reward with adInfo {adInfo} and reward {adReward}"); } void OnAdClicked(LevelPlayAdInfo adInfo) { Debug.Log($"Rewarded ad clicked with ad info {adInfo}"); } void OnAdClosed(LevelPlayAdInfo adInfo) { Debug.Log($"Rewarded ad closed with ad info {adInfo}"); } void OnAdInfoChanged(LevelPlayAdInfo adInfo) { Debug.Log($"Rewarded ad info changed with ad info {adInfo}"); } }
Test and validate
To validate your integration, build the app and run verification tests.Build and test
Build your app for Android or iOS to test the integration. Your app remains in Test Mode until you disable it in the LevelPlay dashboard.Launch the Test Suite (Optional)
Use the LevelPlay Integration Test Suite to verify that each ad network is correctly configured. To enable the Test Suite in your app, call thesetMetaDataOn success callback, launch the Test Suite:LevelPlay.SetMetaData("is_test_suite", "enable");
LevelPlayEvents.onSdkInitializationCompletedEvent += SdkInitializationCompletedEvent;private void SdkInitializationCompletedEvent(){ ... //Launch test suite LevelPlay.LaunchTestSuite();}
Validate the integration
Call the following API to perform an internal check of your package and dependencies:LevelPlay.ValidateIntegration();
Remove the legacy package
After you verify that all ads function correctly and there are no legacy Advertisement APIs in your project, follow these steps to remove the Advertisement Legacy package:- In the Unity Editor, go to Window > Package Manager.
- Select Packages: In Project.
- Locate and select Advertisement Legacy.
- Select Remove.
API and feature mapping reference
Use the following table to map legacy Unity Ads SDK API parameters to the LevelPlay API parameters.Use case | Unity Ads API parameter | LevelPlay parameter | Notes |
|---|---|---|---|
| Initialization ID | | | Applicable to both Android and iOS |
| Initialize SDK | | | Test mode isn't supported by LevelPlay |
| Initialization success event | | | |
| Init failed event | | | |
| Is initialized | | Not supported | Not supported in LevelPlay |
| Set MetaData | | | |
| Load banner | | | The instance must be created |
| Display banner | | | The instance must be created |
| Set banner position | | | Use case passed in constructor or builder |
| Banner load options | | And | |
| Banner options | | And And And And And | |
| Show options | | And And And And And | |
| Hide banner | | | The instance must be created |
| Banner clicked | | | Event Callback on the instance |
| Banner shown | | | Event Callback on the instance |
| Banner hidden | | Not supported | |
| Load rewarded ad | | | Instance must be created |
| Show rewarded ad | | | Instance must be created |
| Load interstitial | | | The instance must be created |
| Show interstitial | | | The instance must be created |
| Ad loaded | | Or | Event Callback on the instance |
| Ad failed to load | | Or | Event Callback on the instance |
| Ad failed to show | | Or | Event Callback on the instance |
| Ad show start | | Or | Event Callback on the instance |
| Ad show click | | Or | Event Callback on the instance |
| Ad show complete | | Or | Event Callback on the instance |
| Is supported | | Not supported | Not supported in LevelPlay |
| Debug mode | | Not supported | Not supported in LevelPlay |
| Package version | | | |
| Is showing | | Not supported | Not supported in LevelPlay |