Ad Integration Guide
Introduction
MG Ads supports 【Splash Ad 19201080】【Banner 72890】【Interstitial 1024768】【Couplet 300600】【Rewarded 1024*768】【Feed】【Embedded】
On the Page Calling Ads, Include Our JavaScript File
<script language="javascript" src="https://ad.mguwp.net/js/h5adsdk.js"></script>
Splash Ad, Exit Ad
For Splash and Exit ad, only the 【AppSetting.config】 configuration file needs to be modified; developers do not need to handle them.
Banner, Interstitial, Couplet, Rewarded Ads
Call the JavaScript method ShowAd(jsonParam) provided by Miracle Games to invoke ads. The parameters are as follows:
| Parameter Name | Parameter Description |
|---|---|
| jsonParam | Ad slot parameters in JSON string format. * unitId = Ad slot ID * adType = Ad slot type: 3.Banner 4.Interstitial 5.Couplet 6.Rewarded * media = Specifies creative type: image, video, web; can be left empty. * comment = Only supported for Rewarded Video ads; a passthrough parameter that must be URL-encoded before passing. This parameter will be received in the ad close event. |
function clientShowMgAd(unitId, adType, media, comment) {
var jsonParam = new Object();
jsonParam.unitId = unitId;
jsonParam.adType = adType;
if (media != undefined && media != "") {
jsonParam.media = media;//Specifies creative type: image, video, web
}
if (comment != undefined && comment != "") {
jsonParam.comment = encodeURIComponent(JSON.stringify(comment));
}
ShowAd(JSON.stringify(jsonParam));//Call MG's ad API
}
Ad Click Event
The click event for MG's Exit Screen ad cannot be captured on the client side. The following event description does not involve the Exit Screen ad.
When a player clicks an ad, the JavaScript method function AdClickEvent(param) will be called. Developers need to implement the internal logic for this method themselves. Sample code for this method is provided in the demo. The parameters are as follows:
| Parameter Name | Parameter Description | Example |
|---|---|---|
| unitId | Ad slot ID passed by the developer | e333abaf22404c4a8d382c1e7ba42076 |
| resourceId | Resource ID | String |
| materialId | Creative ID | String |
function AdClickEvent(param) {
var jsonObj = JSON.parse(param);
var unitId = jsonObj.unitId;
document.getElementById("txtResultMsg").value += ("AdClickEvent ad click event: Ad slot=" + unitId + ", others:" + param + "\r\n");
}
Ad Close Event
The close event for MG's Exit Screen ad cannot be captured on the client side. The following event description does not involve the Exit Screen ad.
When a player closes an ad, the JavaScript method function AdCloseEvent(param) will be called. Developers need to implement the internal logic for this method themselves. Sample code for this method is provided in the demo. The parameters are as follows:
| Parameter Name | Parameter Description | Example |
|---|---|---|
| unitId | Ad slot ID passed by the developer | e333abaf22404c4a8d382c1e7ba42076 |
| advertStatus | Ad slot status | 1: Ad normal; 2: Ad closed by backend; 3: No ad creative |
| The following parameters are only available for Rewarded Video ads | ||
| completeStatus | Ad playback status | 1: Ad playback finished, reward can be issued; 0: Ad playback not finished |
| comment | Passthrough parameter passed by the developer, URL-encoded | abc%2c123 |
| rewardId | MG order number for the reward, used when reporting fulfillment to MG after issuing the in-game reward | String |
| resourceId | Resource ID | String |
| materialId | Creative ID | String |
function AdCloseEvent(param) {
var jsonObj = JSON.parse(param);
var unitId = jsonObj.unitId;
//Rewarded Video Ad
if (unitId=="c10890b4cfbe4f41a450e87c1fb8c22a") {
var completeStatus = jsonObj.completeStatus;
var comment = jsonObj.comment;
var rewardId = jsonObj.rewardId;
var resourceId = jsonObj.resourceId;
var materialId = jsonObj.materialId;
if (completeStatus == 1) {//Rewarded video playback completed
//Issue in-game item
alert("Ad slot: " + unitId + ", Reward ID: " + rewardId + " - item has been issued");
//Asset verification, called after successfully issuing the in-game item
var jsonParam = new Object();
jsonParam.unitId = unitId;
jsonParam.rewardId = rewardId;
jsonParam.resourceId = resourceId;
jsonParam.materialId = materialId;
ReportAdRewardFulfillment(JSON.stringify(jsonParam));//Report to MG
}
}
document.getElementById("txtResultMsg").value += ("AdCloseEvent ad close event: Ad slot=" + unitId + ", others:" + param + "\r\n");
}