Integrate Vungle SDK for Unity

Before You Begin

Requirements

Vungle Unity plugin supports Unity editor version 2017 and higher, and contains following Vungle SDK versions.

  • iOS SDK v6.8.1
    • iOS 9 or higher
    • Xcode12 or higher
  • Android SDK v6.8.1
    • Android 4.0 (Ice Cream Sandwich - API version 14 and higher)
    • Amazon OS 5.4 and higher
    • Requires Java 1.7 or higher for Android
  • Windows SDK v6.8.0
    • Universal Windows Platform (UWP)

Download the Plugin

Download the Vungle plugin for Unity here: https://publisher.vungle.com/sdk/plugins/unity

Reference: Sample App

Refer to the sample app we have provided as you integrate: https://github.com/Vungle/Unity-Plugin

Step 1. Set Up Your Unity Project with the Vungle Unity Plugin

Add the Vungle Unity Plugin to your Unity Project

With your project open in Unity, double-click the downloaded VunglePlugin.unitypackage file to add the Vungle Unity Plugin to your application. When the Import Unity Package window opens, click All to select everything before importing.

Target the Correct Platform in Your Build Settings

To avoid compilation errors during the next step, make sure that your project Build Settings (cmd + Shift + B) are targeting the iOS, Android, or Universal Windows platform.

iOS

Add SKAdNetworkIDs to Info.plist

Configure your app to participate in ad campaigns via the SKAdNetwork framework on iOS 14+. To do this, add the list of our approved partner IDs for advertising attribution to your Info.plist file. Adding the Vungle SKAdNetwork ID and the IDs of all the DSPs to whom you want to sell indicates that your app wants to work with Vungle and accept bids from these buyers.

Refer to Apple’s documentation on configuring the Info.plist properly for ad campaigns to be served. Refer also to the Xcode documentation for help on editing property lists.

Follow these steps to configure your app with SKAdNetworkIDs : 

To set the SKAdNetworkIDs list in Unity:

The Unity package will automatically add the SKAdNetworkIDs into the Info.plist using the post-processing script, VunglePostBuilder.cs. The SKAdNetworkIDs added can be viewed inside the array string[] SKAdNetwork in the script.

To set the SKAdNetworkIDs list manually in Xcode:

  1. Inside the Xcode Project navigator, open the Info.plist file.
  2. Click the add button (+) next to a key in a property list inside the Info.plist file to create a new property key. 
  3. Enter SKAdNetworkItems and select Array in the Type column.
  4. Add a dictionary item, then add a single String item inside the dictionary.
  5. For each String item, add SKAdNetworkIdentifier as the key and the ad network identifier as the value.

Vungle hosts the Vungle SKAdNetwork ID and the list of our buyers' SKAdNetwork IDs in both JSON and XML formats on our website. Note that our lists are updated periodically:

AppTrackingTransparency

Apple has introduced the ATT framework in iOS 14. This framework is not required for our plugin; however, if you plan to use this framework, complete the following steps.

Attach a handler to Vungle.onAppTrackingEvent and receive a callback when the prompt is complete. To trigger the prompt use: Vungle.RequestTrackingAuthorization(). The prompt shows the string message from the plist variable NSUserTrackingUsageDescription inside Editor/Vungle/VunglePostBuilder.cs.

If you do not plan to trigger the prompt, do not add the plist variable. Remove rootDict.SetString("NSUserTrackingUsageDescription", NSUserTrackingUsageDescription); in the method PostProcessIosBuild found in the class VunglePostBuilder.cs.

Android or Amazon

Amazon Appstore

Vungle Android SDK supports Amazon OS 5.4 and higher. You can submit Android APK to the Amazon Appstore, with the additional setup of Unity Amazon Appstore configuration. Refer to the Unity instructions.

Google Play Services

Including Google Play Services with your project allows Vungle to provide a more customized ad experience to the end user, but it's not required. We recommend using version 16.0.0 or higher.

To include Google Play Services, we recommend Google's setup guide on the developer portal. In your app, make sure that the device has a sufficiently updated version of Google Play Services.

Android Dependencies

Vungle SDK for Android requires you to include one of the following dependencies in your build. Either add them manually, or include them in a Gradle template if you use Gradle.

implementation 'androidx.appcompat:appcompat:1.2.0'
// When appcompat is not used, core and localbroadcastmanager can be used instead
// implementation "androidx.core:core:1.3.1"
// implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.0.0"

For Unity 2018.1 and Lower on Android, Add hardwareAccelerated 

hardwareAccelerated is required for Vungle SDK to properly display MREC ads. However, Unity forces this property to be false, even when it is set to 'true' in AndroidManifest.xml file inside your Unity project. To correct this, the Vungle plugin sets it to 'true' using the Gradle post processor script, but this functionality is only available for Unity 2018.2 and higher. Therefore, if you are using Unity 2018.1 or lower (including Unity 2017), you must do this manually by exporting the project to Android Studio and adding the hardwareAccelerated configuration with a value of 'true'.

Sample code:

<application android:hardwareAccelerated="true" ...>

Windows

Update Build and Project Settings

  1. Open Build Settings (Ctrl + Shift + B).
  2. Under Platform, select Universal Windows Platform.
  3. Make sure Build Type is set to "XAML Project" because the Vungle Unity plugin does not support the D3D project build type.
  4. Open Player Settings, and then Publishing Settings.
  5. Make sure internetClient permission is granted in the Capabilities menu.

unity1.png

For Vungle Unity Plugin Versions Lower Than 6.7 Only: Configure Your Universal Windows Platform Project

The steps in this section are not required for Vungle Unity Plugin v6.7.x and higher.

Under the Project tab are two VungleSDKProxy items. Under the Inspector tab, confirm that the following parameters are set correctly in the Select platforms for plugin and Platform settings sections:

Assets/Plugins/VungleSDKProxy.dll:

unity2.png
  • General
    • Auto Reference should be checked
    • Validate References should be checked
  • Select platforms for plugin
    • Editor should be checked
  • Platform settings
    • CPU: Select Any CPU
    • OS: Select Any OS

Assets/Plugins/metro/VungleSDKProxy.winmd:

unity3.png
  • Select platforms for plugin
    • WSAPlayer should be checked
  • Platform settings
    • SDK: Select Any SDK
    • ScriptingBackend: Select Any Scripting Backend

Supported Scripting Backend

Vungle Unity Plugin v6.5.2.1 and higher supports IL2CPP scripting backend, but it is limited to Unity 2018 and higher due to limitations on the Unity side. For Unity 2017, use the .NET scripting backend instead.

Unity Version Supported Scripting Backend
2017 .NET
2018 .NET, IL2CPP
2019 IL2CPP

Step 2: Add Code

In this walkthrough, we initialize all of our Vungle-related code in a script attached to the main Game Object. You can call the Vungle Unity Plugin from any scripts that are appropriate. 

Initialize the SDK

Initialize the SDK as soon as your app starts to give the SDK enough time to cache an ad. To initialize the SDK, you must have the App IDs for the platforms you wish to support. You can find these IDs in the Vungle Dashboard (refer to "Setting Up and Reporting on Placements").

A default placement is created for each app automatically. You must provide its placement ID in this initialization step whether or not you plan to take advantage of the placements functionality. If you create multiple placements, provide all the placement IDs. 

Sample code:

public class VungleScript : MonoBehaviour {
    string appID = "";
string iosAppID = "ios_app_id";
string androidAppID = "android_app_id";
string windowsAppID = "windows_app_id"; #if UNITY_IPHONE appID = iosAppID; #elif UNITY_ANDROID appID = androidAppID; #elif UNITY_WSA_10_0 || UNITY_WINRT_8_1 || UNITY_METRO appID = windowsAppID; #endif Vungle.init(appID);
}

Once the SDK is initialized successfully, it calls the following event:

public static event Action onInitializeEvent;

Refer to the event handling section of the ad format article of your choice.

Contact your account manager about cache-optimized placements to maximize caching performance.

Once an ad is cached successfully, the adPlayableEvent event is called with the placement reference ID matching your  placement. Refer to the ad format article of your choice for more detail.

Integrate Ad Formats

Complete your plugin integration for each ad format that you plan to display in your app. Refer to our instructions for each ad format:

Further Customize Your Ads

Follow the instructions in our Advanced Settings article to fine-tune your app's integration with additional configuration options, such as GDPR, CCPA implementation, and many other settings.

Powered by Creativity Driven by Performance Sign Up Here

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!

Was this article helpful?