Tài liệu

Hỗ trợ

Unity Package integration

Download and integrate the ironSource Unity Plugin into your project to enable ad mediation and monetization features.
Thời gian đọc 3 phútCập nhật lần cuối 2 ngày trước

Prerequisites

Unity LevelPlay mediation supports Unity version 2021.3+, and Android operating systems version 4.4 (API level 19)+. iOS version support is defined per network. ironSource ads and LevelPlay mediation support iOS versions 13+, and XCode versions 16+.

Step 1. Add LevelPlay to your Unity project

You can install the LevelPlay package using two main methods:
  • [Recommended] Add the Ads Mediation package to your project by navigating to Window → Package Manager in Unity. Look for “Ads Mediation” and click the install button. You can also add the package by its name:
    com.unity.services.levelplay
  • Or, Download Unity Plugin Version 9.0.0 (.unitypackage) and import it into your Unity project.
Once installed, you can import the LevelPlay Sample from the Package Manager’s package details view and explore a working integration.

Step 2. Initialize the SDK

If you haven’t done so already, go to the LevelPlay Platform and create a new app. When complete, use your App Key to initialize the SDK:
using Unity.Services.LevelPlay;
public void Start() {
    // Register OnInitFailed and OnInitSuccess listeners
    LevelPlay.OnInitSuccess += SdkInitializationCompletedEvent;
    LevelPlay.OnInitFailed += SdkInitializationFailedEvent;
    // SDK init
    LevelPlay.Init("ThisIsYourAppKey");
}
It is important to register OnInitFailed and OnInitSuccess before initializing LevelPlay as they provide you with important insight: OnInitSuccess – triggered when LevelPlay initialized successfully. After you receive this callback, you can start showing ads in your app. OnInitFailed – triggered when LevelPlay failed to initialize and therefore ads will not show. We recommend trying to initialize LevelPlay later (when internet connection is available, or when the failure reason is resolved).

Step 3. LevelPlay Network Manager

The LevelPlay Network Manager window is a one stop shop for all things LevelPlay. You can find it in Unity’s top navigation bar, under Ads Mediation. From here, you can:
  • Update your LevelPlay SDK.
  • Install & update your preferred Ad Networks. Once installed, you’ll need to configure each ad network separately. Learn more.
  • Get your app’s Info.plist automatically updated with SKAdNetwork IDs according to the ad networks you have installed.
Starting from LevelPlay Unity package 8.8.1, the Unity Ads adapter will be installed by default, in addition to ironSource Ads. For more information about setting up your Unity Ads account, see Unity Ads Integration Guide.

Android

To apply your changes and download the relevant ad network artifacts, use the resolver:
  • Go to: Assets → Mobile Dependency Manager → Android Resolver → Resolve
  • Do this after each change in the LevelPlay Network Manager.
If you’re using Gradle, you can avoid downloading the network artifacts into your project. Instead, the artifacts will be added to your Gradle file during compilation. To enable this process:
  1. Go to: Edit → Project Settings → Player → Android → Publishing Settings
  2. Enable Custom Main Gradle Template
  3. Go to: Assets → Mobile Dependency Manager → Android Resolver → Settings
  4. Select “Patch mainTemplate.gradle”
  5. Save your changes, by pressing “OK”

Step 4. Additional setup

iOS

SKAdNetwork support

LevelPlay will automatically manage this for you as of Unity package version 8.8.1. Open the Network Manager to opt-in, as described in Step 3. In versions 8.10.0 and earlier, you must also enable ironSource SDK SKAN ID automation under Ads Mediation > Developer Settings > LevelPlay Mediation Settings. To manually enable the display of ads while using SDK 7+, make sure to include the SKAdNetwork ID for each of your installed networks in your app property list file (Info.plist):
<key>SKAdNetworkItems</key>
<array>
  <dict>
    <key>SKAdNetworkIdentifier</key>
    <string>su67r6k2v3.skadnetwork</string>
  </dict>
</array>

App transport security settings

  • Add a dictionary called ‘NSAppTransportSecurity‘ on the ‘Top Level Key‘.
  • Inside this dictionary, add a Boolean called ‘NSAllowsArbitraryLoads‘ and set it to YES.
  • Make sure your info.plist does not contain any other exceptions besides ‘NSAllowsArbitraryLoads‘, as this might create a conflict.
  • Find more information on ATS here.
  • To be compliant with Apple’s privacy requirements, you must implement SKAdNetwork attribution as well as the iOS Privacy Manifest. LevelPlay supports both and you can learn more here.

Android

Apps using Android 13+ (API level 33+) 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.

Step 5. Verify your integration

The LevelPlay package provides an easy way to verify that your integration was completed successfully with its integration test suite. Test your app’s integration, verify platform setup, and review ads related to your configured networks. To enable the test suite in your app, call the following before initializing the SDK:
LevelPlay.SetMetaData("is_test_suite", "enable");
After successfully initializing LevelPlay, launch the test suite by calling:
LevelPlay.LaunchTestSuite();
For more details and an implementation example of the LevelPlay integration test suite navigate to this article.

Next steps

Follow our integration guides to implement ad formats: