Integrate Vungle SDK for Unity


Before You Begin

  • iOS SDK 6.5.2
    • Unity 5.4.1+, 2017, 2018 and 2019
    • iOS 9 or higher
    • The Vungle SDK requires that you link the WebKit.framework framework to your project. If you are developing for IOS 7, you must set this framework to 'Optional'. To do this, click on your project in Project Navigator and go to GeneralLinked Frameworks and Libraries. Select WebKit.framework and set the Status to ‘Optional’.
  • Android SDK 6.5.2
    • Unity 5.3.2+, 2017, 2018 and 2019
    • Android 4.0 (Ice Cream Sandwich - API version 14 and above)
    • Amazon OS 5.4 and above
    • requires Java 1.7 for Android

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 UWP platform.

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 at the following link:

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 found on the developer portal at In your app, ensure that the device has a sufficiently updated version of Google Play Services.

Android Dependencies

Vungle SDK for Android requires one of the following dependency to be included in your build. Please add them manually, or if you use a Gradle template you can include them in it.

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

Adding Hardware Acceleration (Android only)

Hardware acceleration is enabled by default if your target API level is set to 14 or above. This option must be enabled for the SDK to properly show Dynamic Template and Native Flex ads. Please make sure your project does not have this option set to false.

Sample code:

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

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 you think are appropriate. 

Initialize the SDK

Note: A default placement is created for each app automatically. You must provide its placement reference 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 reference IDs.

Initialize the SDK as soon as your app starts in order to give the SDK enough time to cache an ad. To initialize the SDK, you will need 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"). 

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 this article.

Please reach out to 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 “Check Ad Availability for a Placement” section of this article.)

Load an Ad for a Placement

For all placements call the loadAd method to load an ad.

public static void loadAd(string placementID)

Make sure that you are using the placementID that is linked to the correct platform.

Sample code:

string placementID;
  placementID = "ios_placement_id";
  placementID = "android_placement_id";
  placementID = "windows_placement_id";


Check Ad Availability for a Placement

Once the SDK finishes caching an ad for a placement, the following event is called:

public static event Action<string, bool> adPlayableEvent;

Sample code:

Vungle.adPlayableEvent += (placementID, adPlayable) => {
  if(placementID == "ios_placement_id") {
    playButtonPlacement1.enabled = adPlayable;

Note:​ For the cache optimized placements, this event is called only when an ad becomes available. Optimized placements will automatically attempt to fill without further action. For all other placements, this event is also called in case of “Load Failed” (adPlayable returns false in this case).

You can also check the ad availability for a placement with the following method:

public static bool isAdvertAvailable(string placementID);


Play an Ad

Important: Do not play an ad until the adPlayableEvent function described above returns 'true'. If you try to play an ad before the adPlayableEvent function returns 'true', the user experience will be adversely affected while the ad tries to load. If deploying to Android, instead use the value returned from isAdvertAvailable() to ensure an ad is available (as adPlayableEvent will not return false when no ad is available).

When there is an ad available for a placement, you can play the ad with the following method:

public static void playAd(string placementID);

Sample code:

Vungle.playAd (placementID); 


Event Handling

You can set up event handlers for all 5 Vungle SDK events surrounding ad presentation.

  • The following event is fired when the SDK starts to play a video ad. This is a great place to pause gameplay, sound effects, animations, etc.
    public static event Action onAdStartedEvent;
  • The following event is fired when the SDK closes an ad. This is a great place to reward your users and resume gameplay, sound effects, animations, etc.
    public static event Action<string, AdFinishedEventArgs> onAdFinishedEvent;

    The AdFinishedEventArgs class consists of the following properties for you to check the result of an ad play:
    public class AdFinishedEventArgs : EventArgs
      //Represents a BOOL whether or not the user clicked the download button.
        public bool WasCallToActionClicked{ get; set;}
      //Represents a bool whether or not the video can be considered a completed view.
        public bool IsCompletedView{ get; set;}
  • The following event is fired when the SDK has changed ad availability status. The isAdPlayable boolean denotes the new playability of a specific placementID.
    public static event Action<string, bool> adPlayableEvent;
    Refer to the “Check Ad Availability for a Placement” section of this article for more details.
  • The following event is fired when the SDK is initialized successfully.
    public static event Action onInitializeEvent;

Sample code:

void initializeEventHandlers() {

    Vungle.onAdStartedEvent += (placementID) => {
        DebugLog ("Ad " + placementID + " is starting!  Pause your game  animation or sound here.");

    Vungle.onAdFinishedEvent += (placementID, args) => {
        DebugLog ("Ad finished - placementID " + placementID + ", was call to action clicked:" + args.WasCallToActionClicked +  ", is completed view:"
                  + args.IsCompletedView);

    Vungle.adPlayableEvent += (placementID, adPlayable) => {
        DebugLog ("Ad's playable state has been changed! placementID " + placementID + ". Now: " + adPlayable);

    Vungle.onInitializeEvent += () => {
        adInited = true;
        DebugLog ("SDK initialized");


OnPause and OnResume Functionality

Add code for the onPause and onResume functionality that enables ads that were paused when an app was backgrounded to resume playing.

void OnApplicationPause(bool pauseStatus) {
    if (pauseStatus) {
    else {


Customization Options

The playAd method can also accept an options dictionary to customize the ad playing experience.

public static void playAd(Dictionary<string,object> options, string placementID);

Note: Rewarded ads are in some cases referred to as incentivized ads; both terms always refer to the same kind of ad. In the SDK code and in our Reporting API, we use the term 'incentivized'.

The options dictionary accepts the following keys:




Sets the orientation of the ad. 

  • For iOS, use VungleAdOrientation:
    public enum VungleAdOrientation
        Portrait = 1,
        LandscapeLeft = 2,
        LandscapeRight = 3,
        PortraitUpsideDown = 4,
        Landscape = 5,
        All = 6,
        AllButUpsideDown = 7
  • For Android, set to true for matchVideo and false for autoRotate.


String of the user key that is passed to identify users in the S2S call (if there are any).


String that is used as the title of the alert dialog presented when a user closes an incentivized ad experience prematurely.


String that is used as the body text of the alert dialog presented when a user closes an incentivized ad experience prematurely.


String title for the close button text of the alert dialog presented when a user closes an incentivized ad experience prematurely.


String title for the close button text of the alert dialog presented when a user closes an incentivized ad experience prematurely.


Minimum disk space

Minimum disk space configuration was introduced in version 6.4.0 to determine the limits for available space on a user’s device before the Vungle SDK initializes and fetch ads. Default value for SetMinimumDiskSpaceForInitialization is 51 MB and SetMinimumDiskSpaceForAd is 50 MB. The size is entered in bytes (not MB).


Disable Hardware ID

For SDK version 6.4.0 onwards, publishers can now restrict from passing Hardware ID from the device to the SDK.

//Set false to opt in for Hardware ID collection by SDK or true to opt out


GDPR: Recommended Implementation

As of May 25th, the General Data Protection Regulation (GDPR) will be enforced in the European Union. To comply with GDPR, developers have two options.

  • Option 1 (recommended): Publisher controls the GDPR consent process at the user level, then communicates the user’s choice to Vungle. To do this, developers can collect the user’s consent using their own mechanism, and then use Vungle APIs to update or query the user’s consent status. Refer to the "GDPR Recommended Implementation Instructions" section for details.
  • Option 2: Allow Vungle to handle the requirements. Vungle will display a consent dialog before playing an ad for a European user, and will remember the user’s consent or rejection for subsequent ads.

GDPR Recommended Implementation Instructions

To use Vungle APIs to update or query the user’s consent status as recommended in Option 1, use the Vungle.Consent enumerator and set the current value with the below two functions.

// The Consent enum is used to represent the user's current GDPR opt-in status
public enum Consent {
    Undefined = 0,
    Accepted = 1,
    Denied = 2

// Sets the user's consent status
void updateConsentStatus(Vungle.Consent consent);

// Sets the user's consent status and also sets a string to track GDPR version
void updateConsentStatus(Vungle.Consent consent, string consentMessageVersion);

// Gets the user's consent status
Vungle.Consent getConsentStatus();


Powered by Creativity Driven by Performance Sign Up Here


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

Was this article helpful?