Petal Ads Publisher Service is an advertising service provided by Huawei to help you monetize mobile data by leveraging Huawei devices and data capabilities. After integrating the advertising service, you can present precise, visually stunning, and high-value ad content within your quick game to generate advertising revenue. The process of integrating this service is as follows:

You can integrate the following ad types:
Petal Ads Publisher Service supports personalized and non-personalized ads, and provides APIs for soliciting user consent and requesting ads based on user consent status.
The value true indicates that the user is under the age of consent and only non-personalized ads can be requested. For each qg.requestConsentUpdate request, the fail callback will be triggered. In this case, the pop-up for user consent should not be displayed. The value false indicates that the user has reached the age of consent.
You need to solicit the consent (for example, in a custom pop-up) from a user and display the complete list of ad technology providers. The following demo is for your reference only.
|
|
|
| Figure 1 Pop-up | Figure 2 Provider list displayed when "here" in Figure 1 is tapped |
You can call APIs to integrate native ads, rewarded ads, or banner ads.
For more details, please refer to the demo.
The nativeAd.onLoad callback is executed upon success.
nativeAd.onLoad((adlist) => {
}) The nativeAd.onError callback is executed upon a failure.
nativeAd.onError((errorObj) => {
})For details, please refer to the demo.
The rewardedVideoAd.onLoad callback is executed upon success.
rewardedVideoAd.onLoad((adlist) => {
}) The rewardedVideoAd.onError callback is executed upon a failure.
rewardedVideoAd.onError((errorObj) => {
})For details, please refer to the demo.
The bannerAd.onLoad callback is executed upon success.
bannerAd.onLoad(()=>{
console.log('bannerAd onload success')
}) The bannerAd.onError callback is executed upon a failure.
bannerAd.onError((e)=>{
console.log('bannerAd onError '+ JSON.stringify(e))
}) For details, please refer to the demo.
The interstitialAd.onLoad callback is executed upon a success. Then interstitialAd.show is called to display the ad.
interstitialAd.onLoad(function (data) {
console.log('onLoad data ' + JSON.stringify(data));
interstitialAd.show();
}); The interstitialAd.onError callback is executed upon a failure.
interstitialAd.onError((e)=>{
console.log('interstitialAd onError '+ JSON.stringify(e))
})interstitialAd.onClose(()=>{
console.log('interstitialAd closed');
interstitialAd.destroy();
})For details, please refer to the demo.
You need to test integrated ads prior to commercial release, and submit them to Huawei for acceptance.
Before the testing, ensure that:
Use the test ad unit ID in the test phase.
Perform self-check based on the following rules:
[Incorrect] Request the ad again in onError after the failure. If onError is triggered every time, it creates an infinite loop of "request ad -> failure -> request ad".
[Recommended] Do not send a request again regardless of whether the request is successful or fails. The service can have one more try only for rewarded ads.
[Incorrect] Display the same global ad in multiple scenarios.
[Recommended] The ad object in each scenario is independent. Use the createXX method to create an ad and register a callback.
[Recommended] Add a delay of several seconds or minutes before calling the show API in the onLoad callback.
The delay cannot exceed 1 hour. Otherwise, the ad will not be counted as valid for settlement.
[Incorrect] Only one tap event is reported for multiple taps on a native ad.
[Incorrect] Only one impression event is reported when a native ad is displayed multiple times. For example, when an ad is displayed to a user for the first time, the reportAdShow API is called to report an impression. However, when the user returns to the ad page from another scenario, the ad remains visible but no impression event is reported.
[Recommended] When the user returns to the ad page and the native ad is still displayed, an impression event needs to be reported. Generally, this logic is processed in onShow.
After the test and Huawei acceptance have been complete, you can prepare the commercial launch of your ads.
checkAdConsent(){
var _this = this;
console.log("checkAdConsent start");
// Note: setUnderAgeOfPromise is optional.
// To request ads for users under the age of consent, call setUnderAgeOfPromise to set the tag for such users before calling requestConsentUpdate().
qg.setUnderAgeOfPromise(false);
// The value true indicates that the user is under the age of consent, and personalized ads cannot be requested. In this case, a failure callback is always executed upon the call of requestConsentUpdate, and no pop-up needs to be displayed.
// Call qg.setUnderAgeOfPromise(false) to obtain user consent.
// Display a pop-up.
// Call requestConsentUpdate to update the status based on the choice made by the user in the pop-up.
qg.requestConsentUpdate({
success: function (data) {
console.log("requestConsentUpdate success data " + JSON.stringify(data));
// If the value of isNeedConsent is false, personalized ads can be requested from Ads SDK. If the value is true, the user is in the EEA or another sensitive region, and user consent must be obtained.
if (data.isNeedConsent==true) {
if (data.consentStatus == 2){
// Call showModal() to display the pop-up for soliciting user consent and call qg.setConsentStatus to set the user consent status. You can also query the user consent status stored locally.
let check=cc.sys.localStorage.getItem("isTrue");
if(check){
console.log ('According to the history, the user has given consent before, and personalized ads can be requested.');
}else{
setTimeout(function () {
showModal();
}, 100);
}
} else if(data.consentStatus == 1){
// Only non-personalized ads are received.
qg.setConsentStatus(1)
qg.setNonPersonalizedAd(1)
}
}else{
// Personalized ads can be requested.
qg.setConsentStatus(0)
qg.setNonPersonalizedAd(0)
setTimeout(_this.showModal.bind(_this), 100);
}
console.log("4444")
},
fail: function (data) {
// The failure callback is executed. Request non-personalized ads.
console.log("requestConsentUpdate fail data " + JSON.stringify(data));
qg.setConsentStatus(1)
qg.setNonPersonalizedAd(1)
},
complete: function () { console.log("5555")}
});
},
// Display a pop-up to solicit user consent and then display a list of all ad technology providers.
// Determine the parameters to be padded when calling the qg.setConsentStatus and qg.setNonPersonalizedAd methods based on the user's consent status.
// Request personalized or non-personalized ads based on the user consent status.
showModal(){
qg.showModal({
title: 'Consent Example',
content: 'SKIP or AGREE',
success (res) {
if (res.confirm) {
console.log ('The user taps OK.')
cc.sys.localStorage.setItem("isTrue",true)
qg.setConsentStatus(0)
qg.setNonPersonalizedAd(0)
} else if (res.cancel) {
console.log('The user taps Cancel.')
cc.sys.localStorage.setItem("isTrue",false)
qg.setConsentStatus(1)
qg.setNonPersonalizedAd(1)
}
}
})
}, var nativeAd;
var adId;
createNativeAd(){
console.log("ad demo : loadNativeAd");
nativeAd = qg.createNativeAd({
adUnitId: "testu7m3hc4gvm",
success: function(code) {
console.log("loadNativeAd loadNativeAd : success");
},
fail: function(data, code) {
console.log("loadNativeAd loadNativeAd fail: " + data + "," + code);
},
complete: function() {
console.log("loadNativeAd loadNativeAd : complete");
}
});
nativeAd.offLoad();
nativeAd.onLoad(function (test) {
adId = test.adList[0].adId;
console.log("ad demo loadNativeAd onLoad NativeAd enter length : " + test.adList.length);
console.log(JSON.stringify(test));
var imgUrlList = test.adList[0].imgUrlList;
console.log("ad demo : loadNativeAd onLoad imgUrlList : " + imgUrlList);
cc.sys.localStorage.setItem("ImageList",imgUrlList);
});
nativeAd.offError();
nativeAd.onError(function (test) {
console.log("ad demo : loadNativeAd onError enter" + test.errCode);
console.log("ad demo : loadNativeAd onError enter" + test.errMsg);
});
nativeAd.load();
}
loadPics(){
// remoteUrl: Image URL.
let remoteUrl=cc.sys.localStorage.getItem("ImageList");
console.log("remoteUrl"+remoteUrl);
cc.assetManager.loadRemote(remoteUrl,{ext:".image"},(err, texture)=>{
console.log("err"+err);
var spriteFrame=new cc.SpriteFrame(texture);
// let newNode=new cc.Node();
// newNode.addComponent(cc.Sprite).spriteFrame=spriteFrame;
this.sprite_node.getComponent(cc.Sprite).spriteFrame=spriteFrame;
this.sprite_node.active=true;
// this.node.addChild(newNode);
// this.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
});
}
loadNativeAdAd(){
this.loadPics();
}
showDownloadButton(){
nativeAd.showDownloadButton({
// adId indicates the ad ID, which is returned by the nativeAd.onLoad callback.
adId : adId,
style : {
left:300,
top:500,
heightType:'normal',
width:300,
minWidth:200,
maxWidth:500,
textSize:50,
horizontalPadding:50,
cornerRadius:22,
normalTextColor:'#FFFFFF',
normalBackground:'#5291FF',
pressedColor:'#0A59F7',
normalStroke:5,
normalStrokeCorlor:'#FF000000',
processingTextColor:'#5291FF',
processingBackground:'#0F000000',
processingColor:'#000000',
processingStroke:10,
processingStrokeCorlor:'#0A59F7',
installingTextColor:'#000000',
installingBackground:'#FFFFFF',
installingStroke:15,
installingStrokeCorlor:'#5291FF'
},
success: (code) => {
console.log("showDownloadButton: success");
},
fail: (data, code) => {
console.log("showDownloadButton fail: " + data + "," + code);
},
complete: () => {
console.log("showDownloadButton : complete");
}
});
}
hideDownloadButton(){
nativeAd.hideDownloadButton({
// adId indicates the ad ID, which is returned by the nativeAd.onLoad callback.
adId : adId,
success: (code) => {
console.log("hideDownloadButton: success");
},
fail: (data, code) => {
console.log(" hideDownloadButton fail: " + data + "," + code);
},
complete: () => {
console.log("hideDownloadButton : complete");
}
});
} // To operate the preloaded rewarded video, you need to create a video object, and then call load to load the video, call onload to listen for video loading, or call onclose to stop listening.
var rewardedVideoAd;
reLoadVideo(){
rewardedVideoAd = qg.createRewardedVideoAd({
adUnitId: "testx9dtjwj8hp",
success: (code) => {
console.log("ad demo : loadAndShowVideoAd createRewardedVideoAd success");
},
fail: (data, code) => {
console.log("ad demo : loadAndShowVideoAd createRewardedVideoAd fail: " + data + "," + code);
},
complete: () => {
console.log("ad demo : loadAndShowVideoAd createRewardedVideoAd complete");
}
});
rewardedVideoAd.onLoad(() => {
console.log('ad demo :ad loaded.')
})
rewardedVideoAd.onError((e) => {
console.error('load ad error:' + JSON.stringify(e));
const errCode = e.errCode
const errMsg = e.errMsg
})
rewardedVideoAd.onClose((res) => {
// if(!this.rewardedVideoAd) return
// this.rewardedVideoAd.offClose(null);
console.log('ad onClose: ' + res.isEnded)
// this.rewardedVideoAd.offLoad(null);
if (res && res.isEnded || res === undefined) {
console.log ('The user finishes the video playback and wins a reward.')
}else{
console.log ('The user has not finished the video playback and does not win a reward.')
}
})
rewardedVideoAd.load()
},
// A rewarded ad needs to be pre-loaded. To achieve this, the preceding logic needs to be triggered once your app is launched. When the success callback is triggered after onLoad is called, display the ad element.
// Every time a player taps the ad playback button, call rewardedVideoAd.show() to play the ad. Call rewardedVideoAd.load() to obtain the next ad during the playback time or before closing an ad.
requestRewardAd(){
rewardedVideoAd.show();
rewardedVideoAd.load();
}, createBannerAd() {
// Obtain the parameters of the current screen.
var sysInfo = qg.getSystemInfoSync();
console.log("on getSystemInfoSync: success =" + JSON.stringify(sysInfo));
// Obtain the height of the current screen, in dp.
var bannerTop = sysInfo.safeArea.height
bannerAd = qg.createBannerAd({
// console.log("createBannerAd");
adUnitId: 'testw6vs28auh3',
adIntervals:30,
style:{
// The screen height minus the ad height is the value of top.
top:bannerTop-57,
left:0,
height:57,
width:360,
}
});
setTimeout(function () {
bannerAd.show()
}, 1000);
},
showBannerAd(){
console.log(bannerAd);
setTimeout(function () {
bannerAd.show();
}, 100);
},
hideBannerAd(){
setTimeout(function () {
bannerAd.hide();
}, 100);
}, var interstitialAd;
loadInterstitialVideoAd() {
if (interstitialAd) {
interstitialAd.destroy();
}
interstitialAd = qg.createInterstitialAd({
adUnitId: testb4znbuh3n2
});
interstitialAd.load({
"channelExtras": {
"customerChannel": "1"
}
});
interstitialAd.onLoad(function (data) {
console.log(
"requestImageAdAndShow onLoad data= " + JSON.stringify(data)
);
interstitialAd.show();
});
interstitialAd.onError(err => {
console.log(" requestImageAdAndShow on error = " + JSON.stringify(err));
});
interstitialAd.onClose(() => {
console.log("requestImageAdAndShow interstitialAd closed");
interstitialAd.destroy(() => {
console.log("destroy");
});
});
interstitialAd.onClick(() => {
console.log("requestImageAdAndShow interstitialAd clicked");
});
};