Get Started with the ironSource Ads network with Multiple Instances for Unity
Before You Start
We support Unity version 5 and up.
Step 1. Add the IronSource Unity Package to Your Project
Follow these steps to add the IronSource Unity Package to your project:
- Download the IronSource Unity Plugin here.
- Make sure your Unity project is opened and import the Unity package.
- Double-click on the extracted file; the different files will be populated automatically as shown below:
Important! 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.
Step 2. Additional Settings for Android
If you do have an AndroidManifest, please uncheck the box and follow the steps below.
- Update AndroidManifest.xml
Add the following to your AndroidManifest.xml:- Manifest Permissions
Add the following permissions to your AndroidManifest.xml file outside the <application> tag:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- Manifest Activities
Add the following activities inside the <application> tag on your manifestAdditions:
<activity android:name="com.ironsource.sdk.controller.ControllerActivity" android:configChanges="orientation|screenSize" android:hardwareAccelerated="true" /> <activity android:name="com.ironsource.sdk.controller.InterstitialActivity" android:configChanges="orientation|screenSize" android:hardwareAccelerated="true" android:theme="@android:style/Theme.Translucent" /> <activity android:name="com.ironsource.sdk.controller.OpenUrlActivity" android:configChanges="orientation|screenSize" android:hardwareAccelerated="true" android:theme="@android:style/Theme.Translucent" />
- Manifest Permissions
- Google Play Services
- Download the support-v4-[version].jar. Add the jar to your project under App/Libs.
- We recommend using Google Play Services as the ironSource Plugin requires the Android Advertising ID to ensure ad inventory at scale. Follow this guide on how to integrate the Google Play Services AAR.
Step 3. Additional Settings for iOS
- Add Ad-Support.framework to Your Xcode Project
Our Unity Plugin usually adds all the required frameworks automatically. In some cases, the AdSupport.framework can’t be added automatically using Unity 5. Verify if the framework has been added and in the case it has not been added automatically, make sure to add it manually. - Update Property List File (Info.plist)
(1) SKAdNetwork Support
To enable the display of ironSource Ads network ads while using SDK 7+, make sure to include the ironSource Ads ad network ID in your app property list file (Info.plist).
- Select Info.plist in the Project navigator in Xcode
- Click the Add button (+) beside a key in the property list editor and press Return
- Type the key name SKAdNetworkItems
- Choose Array from the pop-up menu in the Type column
- Create a dictionary item, and below it a single sting item
- 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.
(2) App Transport Security Settings
In iOS9, Apple has added in controls around ‘ATS’. In order 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.
Step 4. Initialize the Ad Units
Application State
First, 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 the Plugin & Ad Units
When initializing the ironSource SDK, you can specify a specific ad unit, or initialize all the ad units defined in ironSource UI platform.
IronSource.Agent.initISDemandOnly(@NotNull Context context, String appKey, AD_UNIT... adUnits)
You should update your code, and use the same names APIs with updated signatures, as described below.
Step 5. Show a Video Ad to Your Users
We recommend requesting a Rewarded Video ad a short while before you plan on showing it to your users as the loading process can take time.
The ironSource SDK fires several events to inform you of ad availability and completions so you’ll know when to reward your users. To receive these events, register to the ISDemandOnlyRewardedVideoListener of the ad units you set up on the ironSource platform.
IronSource.Agent.setISDemandOnlyRewardedVideoListener(YOUR_REWARDED_VIDEO_LISTENER);
The SDK will notify your ISDemandOnlyRewardedVideoListener of all possible events listed below:
IronSource.Agent.setISDemandOnlyRewardedVideoListener(new ISDemandOnlyRewardedVideoListener() { // Invoked when the RewardedVideo ad load is successful. @Override public void onRewardedVideoAdLoadSuccess(String instanceId){ } // Invoked when the RewardedVideo ad load failed. @Override public void onRewardedVideoAdLoadFailed(String instanceId, IronSourceError error){ } // Invoked when the RewardedVideo ad view is about to open. @Override public void onRewardedVideoAdOpened(String instanceId) { } //Invoked when the RewardedVideo ad view is about to be closed. //Your activity will now regain its focus. @Override public void onRewardedVideoAdClosed(String instanceId) { } // Invoked when the user completed the video and should be rewarded. // If using server-to-server callbacks you may ignore this events and // wait for the callback from the ironSource server. @Override public void onRewardedVideoAdRewarded(String instanceId) { // here you can reward the user according to the given amount. } // Invoked when RewardedVideo call to show a rewarded video has // failed. IronSourceError contains the reason for the failure. @Override public void onRewardedVideoAdShowFailed(String instanceId, IronSourceError error){ } // Invoked when the end user clicked on the RewardedVideo ad @Override public void onRewardedVideoAdClicked(String instanceId){ } });
ironSource provides an error code mechanism to help you understand errors you may run into during integration or live production. See the complete guide here.
Load Rewarded Video
To request a Rewarded Video ad, call the following method:
IronSource.Agent.loadISDemandOnlyRewardedVideo(@NotNull Activity activity, String instanceId);
Check Ad Availability
By correctly implementing the ISDemandOnlyRewardedVideoListener and its functions, you can receive the availability status through the onRewardedVideoLoadSuccess callback.
public void onRewardedVideoLoadSuccess(String instanceId) { }
In addition, you can also ask for the ad availability directly by calling the following function:
boolean available = IronSource.Agent.isISDemandOnlyRewardedVideoAvailable(YOUR_INSTANCE_ID);
Once you save the defined instances for the ironSource Ads network, we will generate an Instance ID for you. You can retrieve this ID from the instance table within the Ad Units & Placements page:
Serve Video Ad
Once a video is available, you are ready to serve this video ad to your user. This is the ideal moment to insert a trigger to encourage your users to watch the video ad.
Serve a video ad by calling the following function:
IronSource.Agent.showISDemandOnlyRewardedVideo(YOUR_INSTANCE_ID);
Step 6. Show an Interstitial Ad to Your Users
Implement the Listener
The ironSource SDK fires several events to inform you of Interstitial Activity. The SDK will notify your delegate of all possible events listed below:
IronSource.Agent.setISDemandOnlyInterstitialListener(new ISDemandOnlyInterstitialListener() { /** Invoked when Interstitial Ad is ready to be shown after load function was called. */ @Override public void onInterstitialAdReady(String instanceId) { } /** invoked when there is no Interstitial Ad available after calling load function. */ @Override public void onInterstitialAdLoadFailed(String instanceId, IronSourceError error) { } /** Invoked when the Interstitial Ad Unit is opened */ @Override public void onInterstitialAdOpened(String instanceId){ } /* * Invoked when the ad is closed and the user is about to return to the application. */ @Override public void onInterstitialAdClosed(String instanceId) { } /** * Invoked when Interstitial ad failed to show. // @param error - An object which represents the reason of showInterstitial failure. */ @Override public void onInterstitialAdShowFailed(String instanceId, IronSourceError error) { } /* * Invoked when the end user clicked on the interstitial ad. */ @Override public void onInterstitialAdClicked(String instanceId) { } })
- The onInterstitialAdOpened() and onInterstitialAdShowSucceeded() events convey that the ad format has taken over the app screen and been displayed but does not indicate that an ad has been successfully served to your end-user.
- Do not assume the callbacks are always running on the main thread. Any UI interaction or updates resulting from ironSource callbacks need to be passed to the main thread before executing.
Load Interstitial
To request an interstitial ad, call the following method:
IronSource.Agent.loadISDemandOnlyInterstitial(@NotNull Activity activity, String instanceId);
Instance ID Once you save the defined instances for the ironSource Ads network, we will generate an Instance ID for you. You can retrieve this ID from the instance table within the Ad Units & Placements page: After you call the loadInterstitial in Step 3, you will be notified when the ad is loaded and ready to be shown to your user through the delegate with the method onInterstitialAdReady which will inform you about ad availability. In addition, you can also ask for the ad availability directly by calling the following function: Once you receive the onInterstitialAdReady callback, you are ready to show an Interstitial Ad to your users. Invoke the following method to serve an Interstitial ad to your users: Serve an interstitial ad to your user by calling the following function: 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: 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):
Check Ad Availability
public void onInterstitialReady(){}
boolean available = IronSource.Agent.isISDemandOnlyInterstitialReady(YOUR_INSTANCE_ID);
Show Interstitial Ad
IronSource.Agent.showISDemandOnlyInterstitial(YOUR_INSTANCE_ID);
Step 7. Verify Your Integration
IronSource.Agent.validateIntegration();
-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.** { *;
}
Done!
You are now ready to start working with ironSource’s Ad Units and Mediation Tools.
What’s Next?
Once you’ve verified your integration with the Integration Helper, follow our integration guides and implement our Ad Units: