Ad SDK Selection and Integration
Introduction
Welcome, dear developer! In today's application market, achieving effective traffic monetization is an important task faced by many game and application developers. The MG advertising platform, as a high-quality ad aggregation platform for Microsoft Store developers, provides developers with various ad resources and powerful monetization solutions. It is important to note that if you plan to integrate the MG Ads SDK for traffic monetization, for applications based on the Microsoft Store, developers need to first port the UWP version. This document will focus on the critical aspect of selecting and integrating the MG Ads SDK. Whether you are developing games using Unity, Cocos, or H5 engines, or applications using C++ or C, the MG Ads SDK can meet your needs. By selecting the appropriate MG Ads SDK and successfully integrating it with your development project, you will be able to embark on a diversified path of ad monetization, leveraging the resource integration capabilities of the MG advertising platform to generate more revenue for your application.
Ad SDK Selection
Selection Based on Engine Version
| Engine Type | Recommended SDK Solution | Applicable Scenarios |
|---|---|---|
| Unity | MG Ads Unity SDK or MG Ads UWP SDK | Cross-platform game development, supports 2D/3D projects |
| Cocos | MG Ads UWP SDK or MG Ads C++ SDK | 2D game development, supports Cocos2d-x v3.7+ |
| Unreal Engine | MG Ads C++ SDK | High-performance graphics requirements |
| Native UWP | MG Ads UWP SDK (NuGet) | Pure UWP application development |
| HTML5/Flash | MG Ads Html5 UWP SDK | Web games, H5 mini-games |
| C/C++ | MG Ads C++ SDK or MG Ads C SDK | Native desktop applications, performance-sensitive applications |
Version Porting Flowchart
Unity Project Integration
Integrate MG Ads UWP SDK
Step 1: Compile the Unity project into a UWP project. Refer to 【Unity Engine to UWP Project Porting UWP】
Step 2: Integrate the MG Ads UWP SDK into the UWP project. Refer to 【UWP Ads C++ SDK Download】
Integrate MG Ads Unity SDK
Step 1: Integrate the MG Ads Unity SDK into the Unity project. Refer to 【Integrate MG Ads Unity SDK in Unity Project】
Step 2: Convert the Unity project to UWP version. Refer to 【Unity Engine to exe Porting UWP】
Cocos Project Integration
Integrate MG Ads UWP SDK (Cocos2d v3.7-v3.15 versions can be ported to UWP)
Step 1: Output the Cocos2d-x project as a UWP project. Refer to 【Cocos2d to UWP Project Porting UWP】
Step 2: Integrate the MG Ads UWP SDK into the UWP project. Refer to 【MG Ads UWP SDK Download】
Integrate MG Ads C++ SDK
Step 1: Output the Cocos2d-x project as a Win32 project. Refer to 【Cocos2d to Win32 Project Porting UWP】
Step 2: Integrate the MG Ads C++ SDK into the Win32 project. Refer to 【MG Ads C++ SDK Download】
H5 or Flash Project Integration
Step 1: Integrate the MG Ads Html5 UWP SDK into the H5 or Flash project. Refer to 【MG Ads Html5 UWP SDK Download】
Step 2: Convert the H5 or Flash project to UWP version. Refer to 【Html5 Porting to UWP Version】
C/C++ Project Integration
Step 1: Integrate the MG Ads C++ SDK into the C/C++ project. Refer to 【MG Ads C++ SDK Download】
Step 2: Convert the C/C++ project to UWP version. Refer to 【C++ Engine Porting to UWP】
Unreal Engine Project Integration
Step 1: Integrate the MG Ads C++ SDK into the Unreal Engine project. Refer to 【MG Ads C++ SDK Download】
Step 2: Convert the Unreal Engine project to UWP version. Refer to 【C++ Engine Porting to UWP】
UWP Project Integration
Step 1: Integrate the MG Ads UWP SDK into the UWP project. Refer to 【MG Ads UWP SDK Download】
Step 2: Publish the UWP version through the UWP project. Refer to 【UWP Packaging and Publishing Process】
Selection Based on Development Language
For application developers, if your application is developed based on a C++ framework, the MG Ads C++ SDK is designed specifically for such projects. After introducing the SDK files, you only need to perform simple environment configuration to start calling ad interfaces. The MG Ads C++ SDK can autonomously create and display ads.
Additionally, MG provides a C version of the ad SDK. For developers accustomed to using the C language for application development, the MG Ads C SDK is more user-friendly. Similar to the integration method of the C++ SDK, you only need to introduce the relevant files of the MG Ads C SDK into the C project, perform simple environment configuration, and then call the ad interfaces to complete ad integration.
Ad SDK Integration
Get SDK
Developers need to first visit the MG official website (https://www.mguwp.net) and find the SDK download link for the corresponding project or application in the developer documentation. Depending on the selected SDK version (such as engine-based or development language architecture), download the appropriate SDK package. The developer documentation also provides example resources and integration documents relevant to your project type.
The MG Ads SDK is an integrated solution. After developers download and integrate the SDK, they can access advertising resources without additional complex operations. This is made possible by MG Ads' ability to aggregate advertising platforms. Developers only need to provide advertising slots and embed the MG Ads SDK code to access these advertising resources, rather than performing separate integration operations for each platform.
SDK Integration Flowchart
Developer Backend Configuration
Before integrating the MG Ads SDK, you need to create an application and corresponding ad placements in the MG Ads Developer Backend. 【Reference】
Development Environment Configuration
Developers first need to go to the MG Ads Platform Documentation Center (https://doc.ad.mguwp.net) and find the SDK download entry for the corresponding project or application in the developer documentation. Download the appropriate SDK package based on the selected SDK version (e.g., based on engine or development language architecture). The developer documentation also provides sample resources, integration documentation, and other relevant content matching your project type.
The MG Ads SDK is an integrated solution. After developers download and integrate the SDK, they can access advertising resources without any additional complex operations. This is made possible by the integration capabilities of the MG Ads aggregation platform. Developers only need to provide ad slots and embed the MG Ads SDK code to access these ad resources, without the need for separate integrations with different platforms.
Initialize SDK
Regardless of the method used to integrate the MG SDK, before calling ad interfaces, you must first complete the initialization of the SDK and the configuration of ad compliance CMP-related operations.
Initialization is the core step to ensure the normal operation of the SDK. It not only establishes effective communication with the server but also loads necessary resources and services based on preset configurations, laying the foundation for the stable operation of subsequent functions. This process is crucial for ensuring accurate responses from ad interfaces, improving user experience, and achieving the expected service effects. Therefore, developers should pay special attention to the correctness and completeness of the initialization.
CMP is the key infrastructure for building user trust, reducing legal risks, and maintaining the sustainability of ad revenue. It ensures data flows under legal and transparent premises, thereby balancing commercial value and privacy protection needs. Therefore, developers must integrate CMP when integrating the ad SDK.
using MiracleGamesAd;
using MiracleGamesAd.Models;
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// Call initialization interface. Required parameters are applied for and created in the MG Ads backend.
var result = await ApplicationManager.Initialize("YOUR_APP_KEY","YOUR_Secret_Key");
if (result.ReturnValue) // Initialization callback interface to check if initialization is complete.
{
}
}
Ad Integration
Get the SDK
Developers first need to visit the MG official website (https://www.mguwp.net) and find the corresponding SDK download entry for their project or application in the developer documentation. Based on the selected SDK version (such as engine-based or development language architecture), download the appropriate SDK package. The developer documentation also provides sample resources and integration guides that match your project type.
The MG Ads SDK is an integrated solution. After developers download and integrate the SDK, they can access ad resources without additional complex operations. This is made possible by the integration capabilities of the MG Ads aggregation platform, where developers only need to provide ad placements and embed the MG Ads SDK code to access these ad resources, without having to perform separate integration steps for different platforms.
The following is a code example for integrating ads using the UWP Ads C# SDK. When integrating, you can find the corresponding integration documentation based on your development engine.
Splash Screen Ad
The splash screen ad placement is typically implemented in the page's load method, within the SDK initialization completion event.
public async void FullScreenAd() // MG FullScreenAd
{
// The "XXXXXXXX" parameter requires the ad key, which is obtained from creating it in the MG Ads backend.
var ad = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.FullScreen);
if (ad.ReturnValue) // Triggers the ad close event when the ad is closed.
{
}
}
Exit Screen Ad
Exit screen ads are triggered when exiting the game. To ensure the pop-up rate of exit screen ads when exiting the game, MG implements exit screen ads in two steps:
- After initialization is complete, load the exit screen ad information into memory.
- When exiting the game, directly open the exit screen ad.
// The "XXXXXXXX" parameter requires the ad key, which is obtained from creating it in the MG Ads backend.
AdvertisingManager.SetupExitunitId("XXXXXXXX");
Banner Ad
public async void ShowBannerAdImage()
{
var opt = new BannerAdSettingOptions(); // Set some configuration parameters for the ad; uses default state if not set.
opt.MediaType = "image"; // Set ad type: image="image", web="web"
// Control the display position of the ad.
opt.VerticalAlignment = VerticalAlignment.Center;
opt.HorizontalAlignment = HorizontalAlignment.Center;
// The "XXXXXXXX" parameter requires the ad key, which is obtained from creating it in the MG Ads backend.
var bannerAd = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Banner, opt);
if (bannerAd.ReturnValue) // Triggers the ad close event when the ad is closed.
{
}
}
Interstitial Ad
public async void ShowInterstitialAdDefault()
{
var opt = new InterstitialAdSettingOptions(); // Set some configuration parameters for the ad; uses default state if not set.
opt.MediaType = "image"; // Set ad type: image="image", web="web", video="video"
// The "XXXXXXXX" parameter requires the ad key, which is obtained from creating it in the MG Ads backend.
var interstitialAd = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Interstitial,opt);
if (interstitialAd.ReturnValue) // Triggers the ad close event when the ad is closed.
{
}
}
Couplet Ad
public async void ShowCoupletAdDefault()
{
var opt = new CoupletAdSettingOptions(); // Set some configuration parameters for the ad; uses default state if not set.
opt.MediaType = "image"; // Set ad type: image="image", web="web"
// The "XXXXXXXX" parameter requires the ad key, which is obtained from creating it in the MG Ads backend.
var coupletAd = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Couplet,opt);
if (coupletAd.ReturnValue) // Triggers the ad close event when the ad is closed.
{
}
}
Rewarded Video
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 parameters
CallbackId = "" // Callback address, can be empty
});
if (rewardAd.Tag is RewardAdCompleteState completeState)
{
if (completeState.IsCompleted)
{
// Game logic issues rewards, then reports verification.
var comment = WebUtility.UrlDecode(completeState.Comment);
await AdvertisingManager.ReportAdRewardFulfillment(completeState.RewardId);
}
}
}
Native Feed
Native feed ads require developers to create and maintain controls, passing the control instance to the SDK.
public async void ShowFeedAdDefault()
{
// Supported developer control types are Panel, ContentControl, UserControl, and their derived classes.
var feedAdSettingOptions = new FeedAdSettingOptions
{
Container = FeedContainer
};
// The "XXXXXXXX" parameter requires the ad key, which is obtained from creating it in the MG Ads backend.
var feed = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Feed, feedAdSettingOptions);
}
Embedded Ad
Embedded ads require developers to create and maintain controls, passing the control instance to the SDK.
public async void ShowEmbededAdDefault()
{
// Supported developer control types are Panel, ContentControl, UserControl, and their derived classes.
var embededAdSettingOptions = new EmbededAdSettingOptions
{
Container = EmbededContainer
};
// The "XXXXXXXX" parameter requires the ad key, which is obtained from creating it in the MG Ads backend.
var embeded = await AdvertisingManager.ShowAd("XXXXXXXX", AdType.Embeded, embededAdSettingOptions);
}
Test Integration
Functional Testing
Run your application on different types of devices and different resolutions to check if ads can load, display, and switch (if automatic refresh is supported) as expected. Ensure that the display of ad content does not experience truncation, deformation, or overlap with other UI elements.
Compatibility Testing
Test whether your application runs stably on various system versions, both with and without ads. Also, consider compatibility with other possible third-party libraries or plugins to ensure that the presence of the MG Ads SDK does not cause any conflicts or resource contention.
Performance Testing
Measure the application performance metrics before and after integrating the MG Ads SDK, such as startup speed, frame rate (for game applications), etc. Ensure that ad loading and display do not cause a noticeable drop in the application's frame rate, guaranteeing an uncompromised user experience. In addition to measuring conventional performance metrics like startup speed and frame rate, attention should also be paid to memory usage during ad loading. For example, on mobile devices, if ad loading leads to high memory usage, it may cause device lag or even application crashes. You can use performance analysis tools (such as Android Profiler on Android or Instruments on iOS) to precisely monitor memory usage and optimize the ad loading logic based on the monitoring results, such as adopting lazy loading strategies or optimizing the loading order of ad resources. For network-dependent ads (like video ads), conduct network condition simulation tests. Test ad loading speed, buffering, and impact on overall user experience under different network bandwidths (e.g., 2G, 3G, 4G, Wi-Fi). If ads fail to load normally or take too long to load under poor network conditions, consider preloading some content or providing offline ad solutions.
Conclusion
This document introduces the process of selecting and integrating the MG Ads SDK. The aggregation functionality of the MG Ads platform allows developers to access ad resources by integrating the SDK. We hope this document helps you complete the SDK integration. If you have any questions or need support, please contact the MG Ads platform customer service team or refer to other developer documentation resources. We wish you success in your development and monetization efforts.