Follow

Advanced Usage - Customizing your Banner Ad

View original article on our GitHub

You can control the position of your banner as well as loading a specific size and getting callbacks events, using the STABannerProperties object.

Positioning your banner

You can show your banner at the bottom or top of your screen, or use a fixed position.

Use a top banner
#if UNITY_IPHONE  
StartAppWrapperiOS.STABannerProperties bannerProp = new StartAppWrapperiOS.STABannerProperties();
bannerProp.position = StartAppWrapperiOS.BannerPosition.TOP;
StartAppWrapperiOS.addBanner(bannerProp);
#endif
Use a bottom banner
#if UNITY_IPHONE  
StartAppWrapperiOS.STABannerProperties bannerProp = new StartAppWrapperiOS.STABannerProperties();
bannerProp.position = StartAppWrapperiOS.BannerPosition.BOTTOM;
StartAppWrapperiOS.addBanner(bannerProp);
#endif
Use a fixed position banner
#if UNITY_IPHONE  
StartAppWrapperiOS.STABannerProperties bannerProp = new StartAppWrapperiOS.STABannerProperties();
bannerProp.useFixedPosition = true;
bannerProp.fixedPosition.x = 0;
bannerProp.fixedPosition.y = 100;
StartAppWrapperiOS.addBanner(bannerProp);
#endif

Controlling the size of your banner

The size of the banner is determined by the "size" parameter which can receive one of the following values

ValueSizeBest fits for
STA_AutoAdSize(recommended) Auto-size detects the width of the device's screen in its current orientation, and provides the optimal banner for this size
STA_PortraitAdSize_320x50 320x50 iPhone/iPod touch in portrait mode
STA_LandscapeAdSize_480x50 480x50 iPhone/iPod touch in landscape mode
STA_PortraitAdSize_768x90 768x90 iPad in portrait mode
STA_LandscapeAdSize_1024x90 1024x90 iPad in landscape mode

Example - loading 320x50 top banner

#if UNITY_IPHONE  
StartAppWrapperiOS.STABannerProperties bannerProp = new StartAppWrapperiOS.STABannerProperties();
bannerProp.position = StartAppWrapperiOS.BannerPosition.TOP;
bannerProp.size = StartAppWrapperiOS.BannerSize.STA_PortraitAdSize_320x50;
StartAppWrapperiOS.addBanner(bannerProp);
#endif

Using Banner Callbacks

Use one of your GameObjects as a delegate to get callbacks from the banner ad. Even an empty GameObject you create for this purpose will do.

  1. Pass the GameObject name on the STABannerProperties.delegateName member to the addBanner() method

    void Start () {
          #if UNITY_IPHONE
          StartAppWrapperiOS.STABannerProperties bannerProp = new StartAppWrapperiOS.STABannerProperties();
          bannerProp.delegateName ="Main Camera";
          StartAppWrapperiOS.addBanner(bannerProp);
          #endif    
    }
  2. Implement the following callbacks in your GameObject script

    public class StartAppGameObject : MonoBehaviour {
       // Use this for initialization
       void Start () {
           #if UNITY_IPHONE    
           StartAppWrapperiOS.STABannerProperties bannerProp = new StartAppWrapperiOS.STABannerProperties();
           bannerProp.delegateName ="Main Camera";
           StartAppWrapperiOS.addBanner(bannerProp);
           #endif    
       }
    
       void didDisplayBannerAd() {
           #if UNITY_IPHONE
           Debug.Log("didDisplayBannerAd");
           #endif    
       }
       void failedLoadBannerAd(string Error) {
           #if UNITY_IPHONE
           Debug.Log("failedLoadBannerAd");
           #endif    
       }
       void didClickBannerAd() {
           #if UNITY_IPHONE
           Debug.Log("didClickBannerAd");
           #endif    
       }
    }
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments