Integrating Admob for Unity + Vungle SDK v.5

Use this article to integrate Admob for Unity with Vungle SDK v. 5 for iOS or Android.

  1. Integrate the Admob for Unity base here: https://developers.google.com/admob/unity/start.

  2. Download the latest Vungle SDK base for each platform here: https://dashboard.vungle.com/sdk.

    • For iOS: place framework files here: /Plugins/IOS/
      For example:
      /Plugins/IOS/VungleSDK.framework

    • For Android: place jar files here: /Plugins/Android/
      For example:
      /Plugins/publisher-sdk-android-5.3.0.jar/

  3. Starting with Vungle SDK v.5, Vungle requires that you pass all placements in order to initialize. To do so, you must download a special Admob Unity Package here: https://vungle.box.com/s/4c69oacqrrcer63wg4v35vrmgsew26ub.

    Or, to build this package yourself, use this gradle script: https://github.com/googleads/googleads-mobile-unity/blob/master/mediation/Vungle/build.gradle.

  4. Set your platform-dependant requirements:
    • For iOS: Set your playersettings to ios 8 or above; otherwise, Unity will not pull down cocoapods correctly. Launch from Unity-IPhone.xcworkspace.

    • For Android: You must resolve your dependencies using Admob’s tool. To do this click Assets Play Services Resolver Android Resolver Resolve.

    If you are building on Windows, the menu options look like this:
    image2.png

    If you are building on Mac, the menu options look like this:
    image1.png
  5. Determine whether you are planning to show a rewarded or interstitial ads:
    • For interstitial ads: Set all placement parameters using the VungleInterstitialMediationExtras SetAllPlacements function.
    • For rewarded ads: Set all placements via the VungleRewardedVideoMediationExtras SetAllPlacements function.

    Code example:

    using GoogleMobileAds.Api.Mediation.Vungle;
    
    
    private void RequestInterstitial()
    {
        #iif UNITY_ANDROID
           string adUnitId = "ca-app-pub-8179651753653275/5515034537";
        #elif UNITY_IPHONE
           string adUnitId = "ca-app-pub-8179651753653275/3316025494";
        #else
           string adUnitId = "unexpected_platform";
        #endif
    
            
        //Create a new empty VIME Object, required to add additional parameters, Interstitial only
        VungleInterstitialMediationExtras extras = new VungleInterstitialMediationExtras();
    
         //All placements must be passed at all times, this is because the SDK doesn't start until
        //admob calls it the first time.
        extras.SetAllPlacements(new string[] { "NONREWA26038", "DEFAULT71817" });
    
        // Create an empty ad request with extra parameters required to load Vungle
        AdRequest request = new AdRequest.Builder().AddMediationExtras(extras).Build();
            
    
        // Initialize an InterstitialAd with the adunit
        interstitial = new InterstitialAd(adUnitId);
        	
    
        // Load the interstitial with the request.
        interstitial.LoadAd(request);
    }
    
    private void RequestRewarded()
    {
            #if UNITY_ANDROID
                string adUnitId = "ca-app-pub-8179651753653275/3571397475";
            #elif UNITY_IPHONE
                string adUnitId = "ca-app-pub-8179651753653275/2306018548";
            #else
                string adUnitId = "unexpected_platform";
            #endif
    
            //Create a new empty VRVME Object, required to add additional parameters, rewarded only
            VungleRewardedVideoMediationExtras extras = new VungleRewardedVideoMediationExtras();
            //Same as above, all placements must be passed at all times, as Admob doesn't initlize Vungle until admob calls it
            extras.SetAllPlacements(new string[] { "NONREWA26038", "DEFAULT71817" });
            //Same as above
            AdRequest request = new AdRequest.Builder().AddMediationExtras(extras).Build();
    
            // Initialize a Rewarded Video Ad
            rewardBasedVideo = RewardBasedVideoAd.Instance;
    
            //Loads an ad with the above parameters
            rewardBasedVideo.LoadAd(request, adUnitId);
     }
    
    private void ShowInterstitial()
    {
    	if (interstitial.IsLoaded())
    	{
        	interstitial.Show();
      	}
    }
    
    private void ShowRewarded()
    {
           if (rewardBasedVideo.IsLoaded())
           {
                rewardBasedVideo.Show();
           }
     }
     
Have more questions? Submit a request

Comments