Migrate to Unity LevelPlay from Unity Mediation

Before you start Make sure to follow the dashboard migration article so that your app can monetize with Unity LevelPlay.

Integrating Unity LevelPlay into your app should be done using the LevelPlay Integration Manager. It will enable you to download the latest versions of ironSource SDK and adapters directly from your Unity development platform. This step-by-step guide shows you how to integrate Levelplay mediation, add the networks and perform relevant code changes. 

    1. Remove “Unity’s Advertisement with Mediation package” from your build
    2. Download ironSource Unity package to your project 
    3. Integrate mediated networks using the Integration manager
    4. Complete iOS settings 
    5. Complete Android settings 
    6. Implement LevelPlay API & Callbacks 
      • Rewarded Video
      • Interstitial
      • Banner
      • Impression events

    Step 1. Remove Unity Mediation Package and component from build

    To avoid conflicts in your project, make sure to remove the Unity Advertisement with Mediation Package from your build. 

    1. Go to Package Manager 
    2. Click on the remove button on the Advertisement with Mediation:
    3. Remove MediationAdapterDependencies.XML file from the current location: Assets/Editor/MediationAdapterDependencies.xml

    Step 2. Add the LevelPlay Unity package to your project

    1. Download the latest Unity Plugin Version: KC | Git
    2. Make sure your Unity project is opened and import the Unity package
    3. Double-click on the extracted file as shown below:

    Using the Unity Editor with the ironSource SDK

    The ironSource SDK is designed to work with the Android & iOS platform. The Unity Editor contains a simulator to work with Unity code. In order to work with our plugin, you must target either an Android or iOS build to test the integration.

    LevelPlay mediation demo app

    The Integration Demo application demonstrates how to integrate LevelPlay mediation in your app.

    Download Unity Demo Application

    Step 3.Add your mediated networks using Unity integration tool 

    Install the adapters of your preferred ad networks. Make sure to follow the ad network integration guides on the menu to your left to properly set up the ad networks.

    To upgrade your SDK or Adapter versions:

    • Go to Ads Mediation > Integration Manager
    • Choose “Install” or “Update”

    After this initial update of the latest ironSource SDK or Adapters, the action button will be changed to “Updated”, and will be disabled.

    Android

    To apply your changes, make sure you use the “Resolve” process. This will download all relevant artifacts, according to your choices.

    Manual resolve

    Go to: Assets → Mobile Dependency Manager → Android Resolver → Resolve

     This action should be performed after each change in the LevelPlay Integration Manager.

    If you’re using Automatic Resolve, all updates will be performed when closing the integration manager window.

    For Gradle users 

    If you’re using LevelPlay Integration Manager for Unity, you will be able to avoid downloading the Android artifacts into your project. Instead, the artifacts will be added to your gradle file during the compilation. 

    To enable this process, follow these steps: 

    1. Go to: Assets → Mobile Dependency Manager → Android Resolver → Settings 
    2. Select “Patch mainTemplate.gradle”
    3. Save your changes, by pressing “OK”

    iOS

    Make sure that Cocoapods is installed:

    Go to: Assets → Mobile Dependency Manager → iOS Resolver → Install Cocoapods

    Step 4. Additional settings for iOS

    Add Ad-Support.framework to your Xcode project

    Our Unity Plugin usually adds all the required frameworks automatically. Verify if the framework has been added and in the case it has not been added automatically, make sure to add it manually.

    SKAdNetwork support

    To enable the display of ironSource Network ads while using SDK 7+, make sure to include the ironSource Ad Network ID in your app property list file (Info.plist). 

    1. Select Info.plist in the Project navigator in Xcode
    2. Click the Add button (+) beside a key in the property list editor and press Return
    3. Type the key name SKAdNetworkItems
    4. Choose Array from the pop-up menu in the Type column
    5. Create a dictionary item, and below it a single sting item  
    6. Enter Key name SKAdNetworkIdentifier, and the key value:
    su67r6k2v3.skadnetwork

    You can also add SKAdNetworkIdentifier  to your Info.plist, by using this code:

    <key>SKAdNetworkItems</key> <array> <dict> <key>SKAdNetworkIdentifier</key> <string>su67r6k2v3.skadnetwork</string> </dict> </array>

    For more information on editing the property list, see the Xcode documentation.

    Universal SKAN Reporting

    To receive copies of winning install-validation postbacks from all of the demand sources for your advertised app, add the NSAdvertisingAttributionReportEndpoint key in your app’s Info.plist.

    1. Select Info.plist in the Project navigator in Xcode
    2. Click the Add button (+) beside a key in the property list editor and press Return
    3. Type the key name NSAdvertisingAttributionReportEndpoint
    4. Choose String from the pop-up menu in the Type column
    5. Type the URL: https://postbacks-is.com 

    Learn more about Universal SKAN reporting here.

    App transport security settings

    To ensure uninterrupted support for ironSource ad delivery across all mediation networks, it’s important to make the following changes in your info.plist:

    • Add in a dictionary called ‘NSAppTransportSecurity‘. Make sure you add this dictionary on the ‘Top Level Key‘.
    •  Inside this dictionary, add a Boolean called ‘NSAllowsArbitraryLoads‘ and set it to YES.
    • Make sure that your info.plist does not contain any other exceptions besides ‘NSAllowsArbitraryLoads‘, as this might create a conflict. Find more information on ATS here.

    Step 5. Additional setup for Android

    Apps updating their target API level to 31 (Android 12) will need to declare a Google Play services normal permission in the manifest file as follows:

    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

    Read more about Google Advertising ID changes here.

    Unity 2020 Requirements

    If you are using Unity 2020+, add the following gradle properties to android/gradle.properties:

    android.enableDexingArtifactTransform=false

    Step 6. Mapping Unity Callbacks & ironSource Callbacks 

    As part of this section you’ll be able to view the ironSource SDK alternative to your current Unity Mediation implementation. 

    Application State

    When using ironSource SDK, you’ll need to pass the state of the application by executing the following event function during the Application Lifecycle.

    Call onApplicationPause in each of the Unity Scenes:

    void OnApplicationPause(bool isPaused) {                 
      IronSource.Agent.onApplicationPause(isPaused);
    }
    

    Init Callback

    Unity:

     public async void Initialize()
       {
           try
           {
               InitializationOptions opt = new InitializationOptions();
               opt.SetGameId(GAME_ID);
               await UnityServices.InitializeAsync(opt);
               OnInitializationComplete();
           }
           catch (Exception e)
           {
               OnInitializationFailed(e);
           }
       }
       public void OnInitializationComplete()
       {
           Debug.Log("Init Success");
       }

    LevelPlay:

    IronSource.Agent.init(appKey);
    IronSourceEvents.onSdkInitializationCompletedEvent += SdkInitializationCompletedEvent;
    private void SdkInitializationCompletedEvent(){}

    For more details on the ironSource initialization callback read  this article.

    Rewarded video

    When using LevelPlay Mediation, you can use LevelPlay automatic loading of rewarded video ad unit. 

    This means that you don’t have to specifically load rewarded video ads as part of your app’s logic, but only verify you have an available ad before providing indication to your user that an ad is ready, and showing the rewarded video ad. 

    As a result, we recommend the following implementation: 

    Unity:

    MediationService.Instance.CreateRewardedAd(rewardedAdUnitId);
    // Load an ad
    rewardedAd.LoadAsync()
    // Show an ad:
    RewardedAd.ShowAsync()

    LevelPlay:

    // Check if ad is ready
     If (IronSource.Agent.isRewardedVideoAvailable())
       {
         // Show an ad 
         IronSource.Agent.showRewardedVideo(); 
       }

    Rewarded video callbacks

    Unity:

    {
    rewardedAd.OnLoaded += OnUnityAdsAdLoaded;
    rewardedAd.OnFailedLoad += OnUnityAdsFailedToLoad;
    rewardedAd.OnShowed += OnUnityAdsShowStart;
    rewardedAd.OnFailedShow += OnUnityAdsShowFailure;
    rewardedAd.OnClicked += OnUnityAdsShowClick;
    rewardedAd.OnClosed += OnUnityAdsClosed;
    rewardedAd.OnUserRewarded += OnUserRewarded;
    await rewardedAd.LoadAsync();
    }

    LevelPlay:

    IronSourceRewardedVideoEvents.onAdAvailableEvent += RewardedVideoOnAdAvailable;
    IronSourceRewardedVideoEvents.onAdUnavailableEvent += RewardedVideoOnAdUnavailable;
    IronSourceRewardedVideoEvents.onAdOpenedEvent += RewardedVideoOnAdOpenedEvent;
    IronSourceRewardedVideoEvents.onAdShowFailedEvent += RewardedVideoOnAdShowFailedEvent;
    IronSourceRewardedVideoEvents.onAdClickedEvent += RewardedVideoOnAdClickedEvent;
    IronSourceRewardedVideoEvents.onAdClosedEvent += RewardedVideoOnAdClosedEvent;
    IronSourceRewardedVideoEvents.onAdRewardedEvent += RewardedVideoOnAdRewardedEvent;

    For more details on the ironSource Rewarded Video callbacks navigate to this article.

    Interstitial

    Unity:

    MediationService.Instance.CreateInterstitialAd(interstitialAdUnitId);
    interstitialAd.OnLoaded += AdLoaded;
    interstitialAd.OnFailedLoad += AdFailedToLoad;
    interstitialAd.OnShowed += AdShown;
    interstitialAd.OnFailedShow += AdFailedToShow;
    interstitialAd.OnClosed += AdClosed;

    LevelPlay:

    IronSource.Agent.loadInterstitial();
    IronSourceInterstitialEvents.onAdReadyEvent += InterstitialOnAdReadyEvent;
    IronSourceInterstitialEvents.onAdLoadFailedEvent += InterstitialOnAdLoadFailed;
    IronSourceInterstitialEvents.onAdOpenedEvent += InterstitialOnAdOpenedEvent;
    IronSourceInterstitialEvents.onAdShowSucceededEvent += InterstitialOnAdShowSucceededEvent;
    IronSourceInterstitialEvents.onAdClickedEvent += InterstitialOnAdClickedEvent;
    IronSourceInterstitialEvents.onAdShowFailedEvent += InterstitialOnAdShowFailedEvent;
    IronSourceInterstitialEvents.onAdClosedEvent += InterstitialOnAdClosedEvent;

    For more details on the ironSource Interstitial callbacks navigate to this article.

    Unity:

    MediationService.Instance.CreateBannerAd(bannerAdUnitId,
    bannerSize, bannerAnchor, bannerOffset);
    
    banner.OnLoaded += OnUnityAdsBannerAdLoaded;
    banner.OnRefreshed += OnUnityAdsBannerOnRefreshed;
    banner.OnFailedLoad += OnUnityAdsBannerOnFailedLoad;
    banner.OnClicked += OnUnityAdsBannerOnClicked;

    LevelPlay:

    IronSource.Agent.loadBanner(IronSourceBannerSize.BANNER, IronSourceBannerPosition.BOTTOM);
    IronSourceBannerEvents.onAdLoadedEvent += BannerOnAdLoadedEvent;
    IronSourceBannerEvents.onAdLoadFailedEvent += BannerOnAdLoadFailedEvent;
    IronSourceBannerEvents.onAdClickedEvent += BannerOnAdClickedEvent;
    IronSourceBannerEvents.onAdScreenPresentedEvent += BannerOnAdScreenPresentedEvent;
    IronSourceBannerEvents.onAdScreenDismissedEvent += BannerOnAdScreenDismissedEvent;
    IronSourceBannerEvents.onAdLeftApplicationEvent += BannerOnAdLeftApplicationEvent;

    For more details on the ironSource Banner  callbacks navigate to this article.

    Impression events

    Unity:

    MediationService.Instance.ImpressionEventPublisher.OnImpression += ImpressionEvent;
    void ImpressionEvent(object sender, ImpressionEventArgs e){}

    LevelPlay:

    IronSourceEvents.onImpressionDataReadyEvent += ImpressionDataReadyEvent;
    private void ImpressionDataReadyEvent(IronSourceImpressionData impressionData){}

    For more details on the ironSource Impression data navigate to this article.

    Step 7. Verify your integration

    The ironSource SDK provides an easy way to verify that your Rewarded Video Mediation integration was completed successfully. To verify your ironSource SDK integration as well as any additional ad networks you have implemented, simply add this method to your project:

    IronSource.Agent.validateIntegration();

    For more details on the ironSource Integration Verification tool navigate to this article.

    For Proguard Users Only

    If you are using ProGuard with the ironSource SDK, you must add the following code to your ProGuard file (Android Studio: proguard-rules.pro or Eclipse: proguard-project.txt):

    -keepclassmembers class com.ironsource.sdk.controller.IronSourceWebView$JSInterface {
    public *;
    }
    -keepclassmembers class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
    }
    -keep public class com.google.android.gms.ads.** {
    public *;
    }
    -keep class com.ironsource.adapters.** { *;
    }
    -keep class com.ironsource.unity.androidbridge.** { *;
    }
    -dontwarn com.ironsource.mediationsdk.**
    -dontwarn com.ironsource.adapters.**
    -keepattributes JavascriptInterface
    -keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
    }

    Done!

    You’re now ready to start working with LevelPlay’s ad units and mediation tools.