Ad 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】
Ad Type Codes: 1. Splash Ad 2. Exit Ad 3. Banner 4. Interstitial 5. Couplet 6. Rewarded 7. Feed 8. Embedded
Splash Ad
The splash ad slot is typically called within the Start() method.
public async void ShowSplashAd()
{
// Parameters:
// unitid: Ad key required, obtained from the MG ad backend. (Required)
// adtype: Ad type code: 1. Splash Ad 2. Exit Ad 3. Banner 4. Interstitial 5. Couplet 6. Rewarded 7. Feed 8. Embedded
// MediaType: Set ad type: image="image", webpage="web", video="video"
AsyncResult asyncResult =await AdvertisingManager._instance.ShowAD(unitid,AdType.FullScreen,new FullScreenAdSettingOptions { MediaType= "image" });
if (asyncResult.ReturnValue)
{
Debug.Log("Ad display completed");
}
else
{
Debug.Log(asyncResult.ErrorMessage);
}
}
Exit Ad
The exit ad is triggered when exiting the game. To ensure the display rate of ads upon game exit, MG implements the exit screen ad in two steps:
- After initialization is complete, load the exit screen ad information into memory.
- When exiting the game, open the exit screen ad directly.
public void ShowExitAD()
{
// Parameters:
// unitid: Ad key required, obtained from the MG ad backend. (Required)
AdvertisingManager._instance.ShowExitAdBlocking("unitid");
}
Banner Ad
public async void ShowBannerAd()
{
// Parameters:
// unitid: Ad key required, obtained from the MG ad backend. (Required)
// adtype: Ad type code:1. Splash Ad 2. Exit Ad 3. Banner 4. Interstitial 5. Couplet 6. Rewarded 7. Feed 8. Embedded
// MediaType: Set ad type: image="image", webpage="web"
AsyncResult asyncResult = await AdvertisingManager._instance.ShowAD(unitid, AdType.Banner, new BannerAdSettingOptions {MediaType= "web"});
if (asyncResult.ReturnValue)
{
Debug.Log("Ad display completed");
}
else
{
Debug.Log(asyncResult.ErrorMessage);
}
}
Interstitial Ad
public async void ShowInterstitialAd()
{
// Parameters:
// unitid: Ad key required, obtained from the MG ad backend. (Required)
// adtype: Ad type code: 1. Splash Ad 2. Exit Ad 3. Banner 4. Interstitial 5. Couplet 6. Rewarded 7. Feed 8. Embedded
// MediaType: Set ad type: image="image", webpage="web", video="video"
AsyncResult asyncResult = await AdvertisingManager._instance.ShowAD(unitid, AdType.Interstitial,new InterstitialAdSettingOptions { MediaType= "image" });
if (asyncResult.ReturnValue)
{
Debug.Log("Ad display completed");
}
else
{
Debug.Log(asyncResult.ErrorMessage);
}
}
Couplet Ad
public async void ShowCoupletAD()
{
// Parameters:
// unitid: Ad key required, obtained from the MG ad backend. (Required)
// adtype: Ad type code: 1. Splash Ad 2. Exit Ad 3. Banner 4. Interstitial 5. Couplet 6. Rewarded 7. Feed 8. Embedded
// MediaType: Set ad type: image="image", webpage="web"
AsyncResult asyncResult = await AdvertisingManager._instance.ShowAD(unitid, AdType.Couplet,new CoupletAdSettingOptions { MediaType= "image" });
if (asyncResult.ReturnValue)
{
Debug.Log("Ad display completed");
}
else
{
Debug.Log(asyncResult.ErrorMessage);
}
}
Rewarded
public async void ShowRewardAD()
{
string comment = "id123,abc,$9.99"; // Passthrough parameter, requires URL encoding
comment = Uri.EscapeDataString(comment);
// Parameters:
// unitid: Ad key required, obtained from the MG ad backend. (Required)
// adtype: Ad type code: 1. Splash Ad 2. Exit Ad 3. Banner 4. Interstitial 5. Couplet 6. Rewarded 7. Feed 8. Embedded
// MediaType: Set ad type: video="video", webpage="web"
RewardAdSettingOptions adsettingOptions = new RewardAdSettingOptions();
adsettingOptions.MediaType = "web";
adsettingOptions.Comment = comment;
AsyncResult asyncResult = await AdvertisingManager._instance.ShowAD(unitid, AdType.Reward, adsettingOptions);
if (asyncResult.ReturnValue)
{
// Report to MG that the rewarded ad reward has been issued
AdvertisingManager._instance.ReportAdRewardFulfillment(asyncResult.rewardAdInfo);
Debug.Log("Ad display completed, reward info: " + asyncResult.rewardAdInfo.rewardADcomment);
}
else
{
Debug.Log(asyncResult.ErrorMessage);
}
}
InformationFlow
Feed ad require the developer to specify the ad's size and position.
public async void ShowInformationFlowAD()
{
Vector3 vector3 = new Vector3(-119, 185, 0);
Vector2 vector2 = new Vector2(200, 50);
// Parameters:
// unitid: Ad key required, obtained from the MG ad backend. (Required)
// adtype: Ad type code: 1. Splash Ad 2. Exit Ad 3. Banner 4. Interstitial 5. Couplet 6. Rewarded 7. Feed 8. Embedded
// parentTransform: Position where the native flow ad should be displayed. (Required)
// vector2Size: Size of the native flow ad. (Required)
// vector3Coordinate: Coordinates of the native flow ad. (Required)
// MediaType: Set ad type: image="image", webpage="web", video="video"
InformationFlowAdSettingOptions adSettingOptions = new InformationFlowAdSettingOptions();
adSettingOptions.parentTransform = adtransform;
adSettingOptions.vector2Size = vector2;
adSettingOptions.vector3Coordinate = vector3;
adSettingOptions.MediaType = "image";
AsyncResult asyncResult = await AdvertisingManager._instance.ShowAD(unitid, AdType.InformationFlow, adSettingOptions);
if (asyncResult.ReturnValue)
{
Debug.Log("Ad display completed");
}
else
{
Debug.Log(asyncResult.ErrorMessage);
}
}
Embedded Ad
Embedded ads require the developer to specify the ad's size and position.
public async void ShowEmbeddedAD()
{
Vector3 vector3 = new Vector3(213, -76, 0);
Vector2 vector2 = new Vector2(200, 200);
// Parameters:
// unitid: Ad key required, obtained from the MG ad backend. (Required)
// adtype: Ad type code: 1. Splash Ad 2. Exit Ad 3. Banner 4. Interstitial 5. Couplet 6. Rewarded 7. Feed 8. Embedded
// parentTransform: Position where the embedded ad should be displayed. (Required)
// vector2Size: Size of the embedded ad. (Required)
// vector3Coordinate: Coordinates of the embedded ad. (Required)
// MediaType: Set ad type: image="image", webpage="web", video="video"
EmbeddedAdSettingOptions adSettingOptions = new EmbeddedAdSettingOptions();
adSettingOptions.parentTransform = adtransform;
adSettingOptions.vector2Size = vector2;
adSettingOptions.vector3Coordinate = vector3;
adSettingOptions.MediaType = "image";
AsyncResult asyncResult = await AdvertisingManager._instance.ShowAD(unitid, AdType.Embedded, adSettingOptions);
if (asyncResult.ReturnValue)
{
Debug.Log("Ad display completed");
}
else
{
Debug.Log(asyncResult.ErrorMessage);
}
}