Ad Integration Guide
Introduction
Before integrating ads, the SDK initialization must be completed first.
MG Ads supports 【Splash Ad 19201080】【Exit Ad】【Banner 72890】【Interstitial 1024768】【Couplet 300600】【Rewarded 1024*768】【Feed】【Embedded】
Splash Ad
The splash ad slot is typically implemented in the page's load method, within the SDK initialization completion event.
public async void SplashAd()
{
//"XXXXXXXX" parameter needs to be passed with the ad key, which comes from the MG ad backend.
var ad = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.FullScreen);
if (ad.ReturnValue)//Triggers ad close event when ad is closed
{
}
}
Exit Ad
The exit ad is triggered when exiting the game. To ensure the pop-up rate of the ad upon game exit, MG recommends loading the exit screen ad information into memory after initialization is complete. When exiting the game, the SDK will automatically open the exit screen ad directly.
The code to load the exit ad is as follows:
//"XXXXXXXX" parameter needs to be passed with the ad key, which comes from the MG ad backend.
AdvertisingManager.SetupExitunitId("XXXXXXXX");
After integrating the exit ad code, the following settings are also required.
-
First, change the Target version on the Properties->Application tab of the main project to 19041 (or a higher version).
-
Right-click Package.appxmanifest and choose to open and edit it with the Xml editor.
-
In the Package tag, add xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities", and supplement rescap in IgnorableNamespaces.
-
Under the Capabilities node, add this line.
-
Save.
Banner Ad
public async void ShowBannerAdImage()
{
var opt = new BannerAdSettingOptions();//Set some configuration parameters for the ad; defaults are used when not set.
opt.MediaType = "image";//Set ad type: image="image", web="web".
//Control the position where the ad is displayed.
opt.VerticalAlignment = VerticalAlignment.Center;
opt.HorizontalAlignment = HorizontalAlignment.Center;
//"XXXXXXXX" parameter needs to be passed with the ad key, which comes from the MG ad backend.
var bannerAd = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Banner, opt);
if (bannerAd.ReturnValue)//Triggers ad close event when ad is closed.
{
}
}
Interstitial Ad
public async void ShowInterstitialAdDefault()
{
var opt = new InterstitialAdSettingOptions();//Set some configuration parameters for the ad; defaults are used when not set.
opt.MediaType = "image";//Set ad type: image="image", web="web", video="video".
//"XXXXXXXX" parameter needs to be passed with the ad key, which comes from the MG ad backend.
var interstitialAd = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Interstitial,opt);
if (interstitialAd.ReturnValue)//Triggers ad close event when ad is closed.
{
}
}
Couplet Ad
public async void ShowCoupletAdDefault()
{
var opt = new CoupletAdSettingOptions();//Set some configuration parameters for the ad; defaults are used when not set.
opt.MediaType = "image";//Set ad type: image="image", web="web".
//"XXXXXXXX" parameter needs to be passed with the ad key, which comes from the MG ad backend.
var coupletAd = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Couplet,opt);
if (coupletAd.ReturnValue)//Triggers ad close event when ad is closed.
{
}
}
Rewarded
public async void ShowRewardAd()
{
var json = "{\"coin\":100}";
var rewardAd = await AdvertisingManager.ShowAd(RewardAdUnitId,
AdType.Reward,
new RewardAdSettingOptions
{
MediaType = "video",//Set ad type: image="image", web="web", video="video".
Comment = WebUtility.UrlEncode(json),//Developer-defined parameter.
CallbackId = ""//Callback address, can be empty.
});
if (rewardAd.Tag is RewardAdCompleteState completeState)
{
if (completeState.IsCompleted)
{
//Game logic issues reward, then report fulfillment.
var comment = WebUtility.UrlDecode(completeState.Comment);
await AdvertisingManager.ReportAdRewardFulfillment(completeState.RewardId);
}
}
}
Feed
Feed ad require the developer to create and maintain the control, and pass the control instance to the SDK.
public async void ShowFeedAdDefault()
{
//Supported developer control types that can be passed are Panel, ContentControl, UserControl, and their derived classes.
var feedAdSettingOptions = new FeedAdSettingOptions
{
Container = FeedContainer
};
//"XXXXXXXX" parameter needs to be passed with the ad key, which comes from the MG ad backend.
var feed = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Feed, feedAdSettingOptions);
}
Embedded
Embedded ads require the developer to create and maintain the control, and pass the control instance to the SDK.
public async void ShowEmbededAdDefault()
{
//Supported developer control types that can be passed are Panel, ContentControl, UserControl, and their derived classes.
var embededAdSettingOptions = new EmbededAdSettingOptions
{
Container = EmbededContainer
};
//"XXXXXXXX" parameter needs to be passed with the ad key, which comes from the MG ad backend.
var embeded = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Embeded, embededAdSettingOptions);
}