Banner Ad
Integration
Step 1. Instantiate Banner Ad
You can instanstiate a Banner ad right after SDK finish it's initialization.
You have to pass the platform specific banner placement id and banner AdPosition
in BannerAd
constructor.
Banner ad supports ad positions of following types:
Position | value | Definition |
---|---|---|
Top | 0 | Show banner at the top of the screen |
Bottom | 1 | Show banner at the bottom of the screen |
public class BlueStackAdsController : MonoBehaviour
{
private BannerAd _bannerAd;
void start() {
Settings settings = new Settings(true);
BlueStackAds.Initialize("app_id", settings, HandleInitCompleteAction);
}
private void HandleInitCompleteAction(InitializationStatus initializationStatus)
{
_bannerAd = new BannerAd(placementId, adPosition);
}
}
Step 2. Register event listeners
BannerAd exposes the following events through it's lifecycle.
Methods | Definition |
---|---|
OnBannerDidLoad | Ad is successfully loaded and SDK is ready to display the ad. |
OnBannerDidFailed | The ad failed to load or display. An additional error parameter of type BlueStackError contains the reason of the failure. |
OnAdClicked | User has clicked the ad. Ad may open a link in browser. |
OnBannerDisplay | The banner ad has been displayed on the screen. |
OnBannerHide | The banner ad has been hidden. |
OnBannerDidRefresh | The banner ad has been refreshed |
OnBannerDidFailToRefresh | The banner ad has been failed to refresh |
To register for banner ad events, add the following code after instantiating BannerAd.
_bannerAd.OnBannerDidLoad += (sender, args) =>
{
Debug.Log("OnBannerDidLoad");
};
_bannerAd.OnBannerDidFailed += (sender, args) =>
{
Debug.LogError("OnBannerDidFailed: " + args.Message);
};
_bannerAd.OnBannerDisplay += (sender, args) =>
{
Debug.Log("OnBannerDisplay");
};
_bannerAd.OnBannerHide += (sender, args) =>
{
Debug.Log("OnBannerHide");
};
_bannerAd.OnAdClicked += (sender, args) =>
{
Debug.Log("OnAdClicked");
};
_bannerAd.OnBannerDidRefresh += (sender, args) =>
{
Debug.Log("OnBannerDidRefresh");
};
_bannerAd.OnBannerDidFailToRefresh += (sender, args) =>
{
Debug.LogError("OnBannerDidFailToRefresh: " + args.Message);
};
Make sure you only register event listener once.
Step 3. Load Banner ad
BannerAd takes AdSize
to load banner.
It also have another Load
method that takes Preference
instance along with AdSize
.
Banner Ad supports following ad sizes:
Ad Size | Definition |
---|---|
Banner | 320x50 |
DynamicBanner | 0x50 |
LargeBanner | 320x100 |
FullBanner | 468x60 |
Leaderboard | 728x90 |
DynamicLeaderboard | 0x90 |
MediumRectangle | 300x250 |
- Without Preference
_bannerAd.Load(AdSize.Banner);
- With Preference
public class BlueStackAdsController : MonoBehaviour
{
...
private RequestBannerAd() {
Preference _preference = new Preference();
Location myLocation = new Location(Location.NONE_PROVIDER)
{
Latitude = 35.757866,
Longitude = 10.810547
};
_preference.SetAge(25);
_preference.SetLanguage("en");
_preference.SetGender(Gender.Male);
_preference.SetKeyword("brand=myBrand;category=sport");
_preference.SetLocation(myLocation, 1);
_preference.SetContentUrl("https://madvertise.com/en/");
_bannerAd.Load(AdSize.Banner, _preference);
}
...
}
Note :
The SetLocation
method takes the following parameters:
- The Location instance.
- The CONSENT_FLAG value (corresponds to a int : 0,1,2 or 3).
- 0 = Not allow to send location.
- 1 = When you managed location according to consent value.
- 2 and 3 = Allow the SDK to managed location directly in accordance with the consent value use TCF v1 or TCF v2, see with the madvertise team it depends on your implementation.
Step 4. Show Banner ad
After loading the banner ad you can request it to be displayed.
_bannerAd.OnBannerDidLoad += (sender, args) =>
{
_bannerAd?.Show();
};
Hide Banner ad
Banner Ad can be set to be hidden also.
_bannerAd.Hide();
Change banner ad position
You can set banner ad position runtime.
_bannerAd.setPosition(adPosition);
Destroy banner ad
Destroy banner ad if you want to create a new one.
_bannerAd.Destroy();