Before requesting the ad, register your ad units with Meson. This is a one-time step and is not required prior to each ad request.
string[] bannerAdUnits = {"AD_UNIT_ID_1","AD_UNIT_ID_2"};
Meson.LoadBannerPluginsForAdUnits(bannerAdUnits);
If you miss to Initialize the SDK, this method will fail to return a response. If your game is distributed on both iOS and Android, you only need to import the plugin once, but you must create different apps and ad units for each platform on Meson UI.
Meson Unity plugin gives a set of options for ad size and ad position. Request a banner ad by calling Meson.RequestBanner(adUnitId,position, AdSize
). This will request for a banner ad and show it on the screen.
#if UNITY_IOS
adUnitId = "YOUR_IOS_AD_UNIT_ID";
#elif UNITY_ANDROID
adUnitId = "YOUR_ANDROID_AD_UNIT_ID";
#endif
Meson.RequestBanner(adUnitId, position, AdSize);
Remove the banner from the screen using DestroyBanner
.
Meson.DestroyBanner (bannerAdUnit);
Track the ad lifecycle for banner ads. All the available events for banner ads are listed below.
MesonManager.BannerAdLoadedEvent += AdLoadedEvent;
// create your handler
private void AdLoadedEvent(string adUnitId)
{
// code you wanna execute
}
//Fired when an ad loads in the banner. Includes the ad height.
public static event Action<string, float> BannerAdLoadedEvent;
// Fired when an ad fails to load for the banner
public static event Action<string, string> BannerAdLoadFailedEvent;
// Fired when a banner ad is clicked
public static event Action<string, Dictionary<string, object>> BannerAdClickedEvent;
// Fired when the user is taken out of the application.
public static event Action<string> BannerAdUserLeftApplicationEvent;
//Fired when the banner has finished presenting screen.
public static event Action<string> BannerAdPresentedScreenEvent;
//Fired when the banner has dismissed the presented screen.
public static event Action<string> BannerAdCollapsedScreenEvent;
//Fired when impression data is received.
public static event Action<string, MesonAdData> BannerAdImpressionTrackedEvent;