Release Notes: (1.7.4)
  • Resolved an issue of missing resources occurs on Unity 5.2+ when using this plugin in a new Unity5.2+ created project.
  • Resolved an issue of plugin colliding on Unity 5+.

Integration Guide - Admob Ad Plugin

Platforms: Android, iOS, Windows Phone 8
Plugin version: 1.7.4
Admob iOS SDK version: 7.4.1
Admob Android SDK version: google-play-services-7.8.95
Admob WindowsPhone8 SDK version: 6.5.13
Supported Unity3d version: 3.5.x, 4.x, 5.x
Download trial version

IMPORTANT RELEASE NOTE:

· >>> For developers targeting Android platform, should upgrade to plugin version 1.6.0 or above, since Google will stop accepting new or updated apps that use the standalone Google AdMob SDK starting Aug 1st, 2014. Learn more...


Here is what developers can expect will change on that date:


· On August 1, 2014, the Play Store will stop accepting new or updated apps that use the standalone Google AdMob SDK. The SDK does not use the Advertising ID, and will therefore be non-compliant with the Google Play Ad Policy on this date.

· Google will stop offering technical support for questions specifically related to the standalone SDK on August 1, 2014.

· Ad serving through the standalone SDK will continue to work after August 1, 2014.

Generally you don't have to dive into the documentation from Admob, simply follow a few steps below to get the plugin integrated in your App in minutes:

[1] Import the AdmobAd[Android|IOS|Universal].unitypackage file to your unity project;

[2] Follow the instructions below to configure the plugin.

· >>> For Android platform, click on the menu item of Unity top menu bar: NeatPlug -> AdmobAd -> Patch Android Configuration. This is for generating a valid AndroidManifest.xml or patching the existing file with AdmobAd support.


· >>> For iOS platform, click on the menu item of Unity top menu bar: NeatPlug -> AdmobAd -> Patch iOS Configuration. This is for automatically adding iOS SDK frameworks, libraries or patching the Info.plist file (if needed) as long as the Xcode project is generated by Unity.


· >>> For Windows Phone 8 platform, no actions needed.

[3] Find AdmobAdAgent Prefab and AdmobAdListener Prefab in Assets/Standard Assets/NeatPlug/Ads/AdmobAd/Prefabs/, open the first scene of your game, drag & drop those two prefabs into the scene.

[4] Okay, the integration is done here. Now set up your Ad by filling in a few properties of the AdmobAdAgent gameObject which you just dropped in the Hierarchy window. To do this, simply select that gameObject, and look at its properties in the Inspector window, you need to fill in:

   · Banner Ad Unit Id [Android|IOS|Windows Phone] - Banner Ad Unit ID, new Admob front-end format: ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN

   · Interstitial Ad Unit Id [Android|IOS|Windows Phone] - Interstitial Ad Unit ID, new Admob front-end format: ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN

   · Test Mode - Check this if you want to test on devices. Caution: Please make sure uncheck this before building for store submission!

   · Tag For Children Directed Treatment - Select "Yes" if you want your content to be treated as child-directed for the purposes of COPPA. Details

   · Auto Load Banner Ad - Check this if you want to load banner Ad automatically.

   · Auto Load Banner Ad In Scenes - In which scenes(levels) you want the banner Ad to be auto-loaded. (Set size to zero for all scenes)

   · Auto Load Banner Ad Type - Select the auto-loaded Ad type.

   · Auto Load Banner Ad Layout - Select the auto-loaded Ad layout.

   · Banner Ad Offset - Specify the auto-loaded Ad placement offset to selected Ad Layout.

   · Dont Hide Bannder Ad When Loading Level - Check this if you want the Banner Ad to retain while loading level.

   · Auto Load Interstitial Ad On Level Loaded - Check this if you want to display interstitial Ad automatically when a scene is loaded.

   · Show Interstitial Ad In Scenes - In which scenes(levels) you want the interstitial Ad to be shown as long as the scene is loaded.


     NOTE: Sample scenes with sample code can be found in Assets/Scenes/NeatPlug/Ads/AdmobAd/.

              Please add all below 3 scenes into your Unity Build Settings -> Scenes In Build:

              SampleScene, SampleSceneNext1, SampleSceneNext2

              You need to fill in your Ad Unit IDs on AdmobAdAgent gameObject in SampleScene.

With Auto Load Banner Ad checked, Ad will show up on device after you compile and run then. Basic users can jump straight to step [7] now.

[5] For advanced users who want to take full control of Ads, e.g. close an Ad after an In-App purchase is made, or preload an Ad for later display etc, see below:

  Call the following functions to initialize and request an Ad:

   · AdmobAd.Instance().Init(...) - Required if you don't apply "Ad Unit Id" property values for AdmobAdAgent.

   · AdmobAd.Instance().LoadBannerAd(...) - Request a Banner Ad.

   · AdmobAd.Instance().LoadInterstitialAd(...) - Request an Interstitial Ad.

  There are other useful public methods that AdmobAd provides, to use them, simply call AdmobAd.Instance().methodName().
Show All   
public void Init(string admobId)
/**
 * Initialization.
 * Set the AdmobId (Site publisher ID or mediation ID).
 *
 * This function is only for backward-compatibility supporting legacy Admob front-end.
 * 
 * NOTE: This function only needs to be called if you don't configure your Admob ID 
 * in AdmobAdAgent gameObject properties.  
 *
 * @param admobId
 *            string - Your Admob ID
 */
public void Init(string admobId)
public void Init(string bannerAdUnitId, string interstitialAdUnitId)
/**
 * Initialization, set the Ad Unit IDs.
 * 
 * This function is for the new Admob frond-end.
 * NOTE: the Ad Unit ID is in the following form:
 * ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN
 * 
 * @param bannerAdUnitId
 *            string - Your Banner Ad Unit ID.
 * 
 * @param interstitialAdUnitId
 *            string - Your Interstitial Ad Unit ID.
 * 
*/
public void Init(string bannerAdUnitId, string interstitialAdUnitId)
public void SetTestMode(bool testMode)
/**
 * Set the test mode.
 *
 * @param testMode
 *             bool - true for Test Mode On, false for Test Mode Off.
 */
public void SetTestMode(bool testMode)
public void LoadBannerAd(AdmobAd.BannerAdType adType, AdmobAd.AdLayout layout, int offsetX = 0, ... )
/**
 * Load a Banner Ad.
 * 
 * @param adType
 *           BannerAdType - Type of the Ad.
 * 
 * @param layout
 *           AdLayout - In which layout the Ad should display.
 * 
 * @param offsetX
 *           int - The horizontal offset of the Ad, if the layout is set to left, 
 *                 the offset is from the left edge of screen to the left edge of 
 *                 the Ad; if the layout is set to right, the offset is from the 
 *                 right edge of screen to the right edge of the Ad. 
 *                 The offset is in pixels.
 * 
 * @param offsetY
 *           int - The vertical offset of the Ad, if the layout is set to top, 
 *                 the offset is from the top edge of screen to the top edge of 
 *                 the Ad; if the layout is set to bottom, the offset is from the 
 *                 bottom edge of screen to the bottom edge of the Ad. 
 *                 The offset is in pixels.                 
 * 
 * @param hide
 *           bool - whether the ad should keep being invisible after loaded,
 *                  true for making the ad hidden, false for showing the 
 *                  ad immediately. if the parameter is set to true, then 
 *                  you need to programmatically display the ad by calling 
 *                  ShowBannerAd() after you get notified with event
 *                  OnReceiveAd from AdmobAdListener.
 * 
 * @param extras
 *           Dictionary - The extra parameters of Ad request.
 * 
 * @param tagForChildren
 *           TagForChildrenDirectedTreatment - Set TagForChildrenDirectedTreatment flag,
 *           More information, please refer to: 	
 *           https://developers.google.com/mobile-ads-sdk/docs/admob/additional-controls#play-coppa
 * 
 *           Valid values:
 * 
 *           Unset - Ad requests will include no indication of how you would like your content treated 
 *                   with respect to COPPA.
 * 
 *           Yes - You will indicate that your content should be treated as child-directed for 
 *                 purposes of COPPA.
 * 
 *           No - You will indicate that your content should NOT be treated as child-directed for 
 *                purposes of COPPA.
 * 
 */
public void LoadBannerAd(AdmobAd.BannerAdType adType, AdmobAd.AdLayout layout, 
                          int offsetX = 0, int offsetY = 0, 
                          bool hide = false, 
                          Dictionary<string, string> extras = null, 
                          TagForChildrenDirectedTreatment tagForChildren = Unset)
public void LoadBannerAd(Vector2 adSize, AdmobAd.AdLayout layout, Vector2 offset = Vector2.zero, ... )
/**
 * Load a Banner Ad.
 * 
 * @param adSize
 *           Vector2 - Customized size of the Ad.
 *            
 *           adSize.x - The width of the Ad, in pixels.
 *           adSize.y - The height of the Ad, in pixels. 
 * 
 * @param layout
 *           AdLayout - In which layout the Ad should display.
 * 
 * @param offset
 *           Vector2 - The offset of the Ad.
 * 
 *           offset.x - The horizontal offset of the Ad, if the layout is set to left, 
 *                 the offset is from the left edge of screen to the left edge of 
 *                 the Ad; if the layout is set to right, the offset is from the 
 *                 right edge of screen to the right edge of the Ad. 
 *                 The offset is in pixels.	
 *           offset.y - The vertical offset of the Ad, if the layout is set to top, 
 *                 the offset is from the top edge of screen to the top edge of 
 *                 the Ad; if the layout is set to bottom, the offset is from the 
 *                 bottom edge of screen to the bottom edge of the Ad. 
 *                 The offset is in pixels.                 
 * 
 * @param hide
 *           bool - whether the ad should keep being invisible after loaded,
 *                  true for making the ad hidden, false for showing the 
 *                  ad immediately. if the parameter is set to true, then 
 *                  you need to programmatically display the ad by calling 
 *                  ShowBannerAd() after you get notified with event
 *                  OnReceiveAd from AdmobAdListener.
 * 
 * @param extras
 *           Dictionary - The extra parameters of Ad request.
 * 
 * @param tagForChildren
 *           TagForChildrenDirectedTreatment - Set TagForChildrenDirectedTreatment flag,
 *           More information, please refer to: 	
 *           https://developers.google.com/mobile-ads-sdk/docs/admob/additional-controls#play-coppa
 * 
 *           Valid values:
 * 
 *	         Unset - Ad requests will include no indication of how you would like your content treated 
 *                   with respect to COPPA.
 * 
 *           Yes - You will indicate that your content should be treated as child-directed for 
 *                 purposes of COPPA.
 * 
 *           No - You will indicate that your content should NOT be treated as child-directed for 
 *                purposes of COPPA.
 * 
 */
public void LoadBannerAd(Vector2 adSize, AdmobAd.AdLayout layout, 
                          Vector2 offset = Vector2.zero, bool hide = false, 
                          Dictionary<string, string> extras = null, 
                          TagForChildrenDirectedTreatment tagForChildren = Unset)
public void LoadBannerAd(AdmobAd.BannerAdType adType, int top, int left, bool hide = false, ... )
 * Load a Banner Ad and place it at specified absolute position.
 * 
 * Please note that the Ad won't display if the top or left applied
 * makes the Ad display area outside the screen.
 * 
 * @param adType
 * 			BannerAdType - the type of Ad.
 * 
 * @param top
 * 			int - the top margin (in pixels) for placing Ad in absolute position.
 * 
 * @param left
 * 			int - the left margin (in pixels) for placing Ad in absolute position. 
 * 
 * @param hide
 *           bool - whether the ad should keep being invisible after loaded,
 *                  true for making the ad hidden, false for showing the 
 *                  ad immediately. if the parameter is set to true, then 
 *                  you need to programmatically display the ad by calling 
 *                  ShowBannerAd() after you get notified with event
 *                  OnReceiveAd from AdmobAdListener.
 * 
 * @param extras
 *           Dictionary - The extra parameters of Ad request.
 * 
 * @param tagForChildren
 *           TagForChildrenDirectedTreatment - Set TagForChildrenDirectedTreatment flag,
 *           More information, please refer to: 	
 *           https://developers.google.com/mobile-ads-sdk/docs/admob/additional-controls#play-coppa
 * 
 *           Valid values:
 * 
 *           Unset - Ad requests will include no indication of how you would like your content treated 
 *                   with respect to COPPA.
 * 
 *           Yes - You will indicate that your content should be treated as child-directed for 
 *                 purposes of COPPA.
 * 
 *           No - You will indicate that your content should NOT be treated as child-directed for 
 *                purposes of COPPA.
 * 
 */
public void LoadBannerAd(AdmobAd.BannerAdType adType, int top, int left, 
	                 bool hide = false, Dictionary<string, string> extras = null, 
	                 TagForChildrenDirectedTreatment tagForChildren = Unset)
public void ShowBannerAd()
/**
 * Show the Banner Ad.
 * 
 * This sets the banner ad to be visible.
 */
public void ShowBannerAd()
public void HideBannerAd()
/**
 * Hide the Banner Ad.
 * 
 * This sets the banner ad to be invisible again.
 */
public void HideBannerAd()
public void RefreshBannerAd()
/**
 * Refresh the Banner Ad.
 * 
 * This initiates a new ad request to plugin.
 */
public void RefreshBannerAd()
public void RepositionBannerAd(AdmobAd.AdLayout layout, int offsetX = 0, int offsetY = 0)
/**
 * Reposition the Banner Ad.
 * 
 * @param layout
 *           AdLayout - In which layout the Ad should display.
 * 
 * @param offsetX
 *           int - The horizontal offset of the Ad, if the layout is set to left, 
 *                 the offset is from the left edge of screen to the left edge of 
 *                 the Ad; if the layout is set to right, the offset is from the 
 *                 right edge of screen to the right edge of the Ad. 
 *                 The offset is in pixels.
 * 
 * @param offsetY
 *           int - The vertical offset of the Ad, if the layout is set to top, 
 *                 the offset is from the top edge of screen to the top edge of 
 *                 the Ad; if the layout is set to bottom, the offset is from the 
 *                 bottom edge of screen to the bottom edge of the Ad. 
 *                 The offset is in pixels. 
 */
public void RepositionBannerAd(AdmobAd.AdLayout layout, int offsetX = 0, int offsetY = 0)
public void DestroyBannerAd()
/**
 * Destroy the Banner Ad.
 */
public void DestroyBannerAd()
public void LoadInterstitialAd(bool hide = false, Dictionary<string, string> extras = null)
/**
 * Load an Interstitial Ad.	 
 * 
 * @param hide (Optional, default false)
 *           bool - whether the ad should keep being invisible after loaded,
 *                  true for making the ad hidden, false for showing the 
 *                  ad immediately. if the parameter is set to true, then 
 *                  you need to programmatically display the ad by calling 
 *                  ShowInterstitialAd() after you get notified with event
 *                  OnReceiveAdInterstitial from AdmobAdListener.
 *
 * @param extras (Optional, default null)
 *           Dictionary<string, string> - The extra parameters of Ad request.
 */
public void LoadInterstitialAd(bool hide = false, Dictionary<string, string> extras = null)
public void ShowInterstitialAd()
/**
 * Show the Interstitial Ad.
 * 
 * This sets the Interstitial ad to be visible.
 */
public void ShowInterstitialAd()
public void DisableAd()
/**
 * Disable all Ads (Banners and Interstitials).
 * 
 * This function is very useful when you want to disable the Ads after
 * the user makes an In-App Purchase. In this case, you should call
 * this function in OnPurchaseCompleted() event handler of an IAP
 * plugin. 
 * 
 * This function also persists the state on the user's device so you
 * don't need to set any variable in the PlayerPrefs.	
 */
public void DisableAd()
public void EnableAd()
/**
 * Enable Ads (Banners and Interstitials).
 * 
 * This function is for re-enabling the Ads after you called DisableAd().
 * After calling this function, you will be able to call LoadBannerAd() or
 * LoadInterstitialAd() then. And if the "Auto Load" switch is turned on, the
 * Ad will continue to be served then.
 * Persistent state is also taken care of, you don't need to set any variables
 * in the PlayerPrefs either.	
 */
public void EnableAd()
public void IsAdEnabled()
/**
 * Check if Ad is enabled or not.
 * 
 * This function is for getting the current state of the Ad.
 * 
 * @result bool - True if the Ad is enabled, false if the Ad has 
 *                been disabled by calling DisableAd().
 */
public bool IsAdEnabled()

[6] For advanced users who need to handle Ad events, e.g. reposition the game HUD bar as long as an Ad is displayed. Read this:

  Follow the instructions to handle Ad events:

  · Select the dropped AdmobAdListener gameObject, locate the AdmobAdListener.cs script, open it and make some modifications.

  These callbacks are exposed in the script, you can supply your own implementations in them.
Show All   
void OnAdShown() { ... }
/**
 * Fired when the banner Ad is shown.
 */
void OnAdShown()
{
    /// Your code here...   
}
void OnAdHidden() { ... }
/**
 * Fired when the banner Ad is hidden.
 */
void OnAdHidden()
{
    /// Your code here...   
}
void OnReceiveAd() { ... }
/**
 * Fired when a banner Ad is received successfully.
 */
void OnReceiveAd()
{
    /// Your code here...   
}
void OnFailedToReceiveAd(string err) { ... }
/**
 * Fired when a banner Ad fails to be received.
 * 
 * @param err
 *          string - The error string
 */
void OnFailedToReceiveAd(string err)
{
    /// Your code here...
}
void OnPresentScreen() { ... }
/**
 * Fired when a Banner Ad screen is presented.
 */
void OnPresentScreen()
{
    /// Your code here...   
}
void OnDismissScreen() { ... }
/**
 * Fired when a Banner Ad screen is dismissed.
 */
void OnDismissScreen()
{
    /// Your code here...   
}
void OnLeaveApplication() { ... }
/**
 * Fired when the App loses focus after a Banner Ad is clicked.
 */
void OnLeaveApplication()
{
    /// Your code here...
}
void OnReceiveAdInterstitial() { ... }
/**
 * Fired when an Interstitial Ad is received successfully.
 */
void OnReceiveAdInterstitial()
{
    /// Your code here...
}
void OnFailedToReceiveAdInterstitial(string err) { ... }
/**
 * Fired when an Interstitial Ad fails to be received.
 *
 * @param err
 *          string - The error string
 */
void OnFailedToReceiveAdInterstitial(string err)
{
    /// Your code here...
}
void OnPresentScreenInterstitial() { ... }
/**
 * Fired when an Interstitial Ad screen is presented.
 */
void OnPresentScreenInterstitial()
{
    /// Your code here...
}
void OnDismissScreenInterstitial() { ... }
/**
 * Fired when an Interstitial Ad screen is dismissed.
 */
void OnDismissScreenInterstitial()
{
    /// Your code here...
}
void OnLeaveApplicationInterstitial() { ... }
/**
 * Fired when the App loses focus after an Interstitial Ad is clicked.
 */
void OnLeaveApplicationInterstitial()
{
    /// Your code here...
}

[7] Build your App now. To compile for iOS platform, you need to have Xcode 4.5 (with iOS SDK v6) or above installed.

[8] Test and verify if the Ad can show up as expected, don't forget to test if the Ad is clickable and if the Ad window can be opened. It is suggested that you should turn on Test Mode (check "Test Mode" property of AdmobAdAgent gameObject or call AdmobAd.Instance().SetTestMode(true).) Also it would be helpful for you to address issues if you take a look at the logcat output (Android) or xcode debug console (iOS) or VisualStudio debug console (WindowsPhone) to find the debug / error / warning messages.

IMPORTANT: Don't forget to turn off test mode before you build your release binary for appstore submission.

[EOF] Should you have any questions or encounter any problems while integrating the plugin, please do not hesitate to shoot us an email at support@neatplug.com, we will be more than happy to help you. Thanks for choosing NeatPlug solutions!