Skip to main content

Integration Guide

Introduction

Before integrating ads, you must first complete SDK initialization.

MG Ads support the following formats: 【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.


Platform::String^ MainPage::SplashAd()
{
try
{
//The "XXXXXXXX" parameter needs to be the ad key, which is obtained from the MG ad backend.
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd("XXXXXXXX", MiracleGamesAd::Models::AdType::FullScreen));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
if (result->ReturnValue) //Triggers the ad close event when the ad is closed
{

}
});
}
catch (...){} //Add exception handling mechanism to prevent game crashes.
return "";
}

Exit Ad

The exit ad is triggered when exiting the game. To ensure the display rate of ads upon game exit, MG recommends loading the exit screen ad information into memory immediately 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:


//The "XXXXXXXX" parameter needs to be the ad key, which is obtained from the MG ad backend.
try
{
MiracleGamesAd::AdvertisingManager::SetupExitunitId(“XXXXXXXX”);
}
catch (...){} //Add exception handling mechanism to prevent game crashes.

After integrating the exit screen ad code, the following additional settings are required.

  1. First, change the Target version on the Properties->Application tab of the main project to 19041 (or a version higher than this).
  2. Right-click Package.appxmanifest and select the XML Editor to open and edit it.
  3. Add xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" to the Package tag, and add rescap to IgnorableNamespaces.
  4. Under the Capabilities node, add this line: <rescap:Capability Name="confirmAppClose"/>
  5. Save the file.

Platform::String ^MainPage::MainScreen_Binner()
{
try
{
auto opt = ref new MiracleGamesAd::Models::BannerAdSettingOptions(); //Set some configuration parameters for the ad; defaults are used if not set.
opt->MediaType = "image"; //Set the ad type: image="image", webpage="web"
//Control the display position of the ad
opt->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Center;
opt->VerticalAlignment = Windows::UI::Xaml::VerticalAlignment::Bottom;
//The "XXXXXXXX" parameter needs to be the ad key, which is obtained from the MG backend.
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd(“XXXXXXXX”, MiracleGamesAd::Models::AdType::Banner, opt));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
if (result->ReturnValue) //Triggers the ad close event when the ad is closed
{

}
});
}
catch (...){} //Add exception handling mechanism to prevent game crashes.
return "";
}

Interstitial Ad


Platform::String^ MainPage::MainScreen_TableAD()
{
try
{
auto opt = ref new MiracleGamesAd::Models::InterstitialAdSettingOptions(); //Set some configuration parameters for the ad; defaults are used if not set.
opt->MediaType = "image"; //Set the ad type: image="image", webpage="web", video="video"
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd(“XXXXXXXX”, MiracleGamesAd::Models::AdType::Interstitial, opt));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
if (result->ReturnValue) //Triggers the ad close event when the ad is closed
{

}
});
}
catch (...){} //Add exception handling mechanism to prevent game crashes.
return "";
}

Couplet Ad


Platform::String ^ MainPage::MainScreen_Couplet()
{
try
{
auto opt = ref new MiracleGamesAd::Models::CoupletAdSettingOptions(); //Set some configuration parameters for the ad; defaults are used if not set.
opt->MediaType = "image"; //Set the ad type: image="image", webpage="web"
//The "XXXXXXXX" parameter needs to be the ad key, which is obtained from the MG backend.
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd(“XXXXXXXX”, MiracleGamesAd::Models::AdType::Couplet, opt));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
if (result->ReturnValue) //Triggers the ad close event when the ad is closed
{

}
});
}
catch (...){} //Add exception handling mechanism to prevent game crashes.
return "";
}

Rewarded Ad

void ShowAdReword() {
auto opt = ref new MiracleGamesAd::Models::RewardAdSettingOptions();
opt->MediaType = "image"; //Set the ad type: image="image", webpage="web", video="video"
opt->Comment = "{\"coin\":100}"; //Developer-defined parameter
//The "XXXXXXXX" parameter needs to be the ad key, which is obtained from the MG backend.
auto initTask = Concurrency::create_task(MiracleGamesAd::AdvertisingManager::ShowAd("XXXXXXXX", MiracleGamesAd::Models::AdType::Reward, opt));
initTask.then([](MiracleGamesAd::Services::Core::Common::AsyncProcessResult^ result)
{
auto completeState = dynamic_cast<MiracleGamesAd::Models::RewardAdCompleteState^>(result->Tag);
if (completeState != nullptr)
{
if (completeState->IsCompleted)
{
auto comment = completeState->Comment; //Developer-defined parameter
MiracleGamesAd::AdvertisingManager::ReportAdRewardFulfillment(completeState->RewardId);
}
}
});
}