This function depends on the services provided by the Petal Ads SDK, which may collect users' personal data. Inform users that their personal data will be collected and guide them to read the corresponding privacy policy before they use this function in your quick game.
API | Description |
|---|---|
Consent APIs | |
Sets the flag indicating whether a user is below the age of consent. | |
Requests an update to the user's consent status. | |
Sets a user's consent status. | |
Sets whether to process ad requests according to the COPPA. | |
Sets whether to process ad requests in a manner appropriate for users below the age of consent. | |
qg.setAdContentClassification(string adContentClassification) | Sets the maximum ad content rating. |
Sets whether to request non-personalized ads. | |
Native ad APIs | |
Creates a native ad component. If a native ad component has been created before, the API returns the existing one. | |
Obtains ad data. | |
Reports ad impressions. Only one report is valid for each ad. adId is a field in the ad data obtained by using the load method. | |
Reports ad clicks. Only one report is valid for each ad. adId is a field in the ad data obtained by using the load method. | |
Sets the callback for successful ad loading. | |
Removes the listener for successful native ad loading. | |
Listens for native ad error events. | |
Removes the listener for native ad loading errors. | |
Sets whether to process ad requests according to the COPPA. | |
nativeAd.setTagForUnderAgeOfPromise(number underAgeOfPromiseStr) | Sets whether to process ad requests in a manner appropriate for users below the age of consent. |
nativeAd.setAdContentClassification(string adContentClassification) | Sets the maximum ad content rating. |
Sets whether to request non-personalized ads. | |
Downloads the app associated with the native ad from the ad landing page. | |
Shows the control button. adId is a field in the ad data obtained using the load method. | |
Hides the control button. adId is a field in the ad data obtained using the load method. | |
Destroys a native ad. | |
Rewarded video ad APIs | |
Creates a rewarded video ad. | |
Manually obtains ads for refreshing the ad content. | |
Displays the rewarded video ad. The rewarded video ad component is hidden by default, and calling show() will make it visible. | |
Sets the callback for successful ad loading. | |
Removes the listener for successful rewarded video ad loading. | |
Listens for rewarded video ad closing events. A rewarded video ad can be closed only when the user actively closes it. | |
Removes the listener for rewarded video ad closing events. | |
Listens for rewarded video ad loading error events. | |
Removes the listener for rewarded video ad loading error events. | |
rewardedVideoAd.setTagForChildProtection(number childProtection) | Sets whether to process ad requests according to the COPPA. |
rewardedVideoAd.setTagForUnderAgeOfPromise(number underAgeOfPromiseStr) | Sets whether to process ad requests in a manner appropriate for users below the age of consent. |
rewardedVideoAd.setAdContentClassification(string adContentClassification) | Sets the maximum ad content rating. |
Sets whether to request non-personalized ads. | |
Destroys a rewarded video ad. | |
Banner ad APIs | |
Creates a banner ad component. If a banner ad component has been created before, the API returns the existing one. | |
Loads and displays a banner ad. | |
Hides a banner ad. | |
Listens for banner ad error events. | |
Removes the listener for banner ad error events. | |
Listens for banner ad loading events. | |
Removes the listener for banner ad loading events. | |
Listens for banner ad closing events. | |
Removes the listener for banner ad closing events. | |
Destroys a banner ad. | |
Interstitial ad APIs | |
Adds the content of an interstitial ad. | |
Loads an interstitial ad. | |
Displays an interstitial ad. | |
Listens for interstitial ad loading events. | |
Removes the listener for interstitial ad loading events. | |
Listens for interstitial ad error events. | |
Removes the listener for interstitial ad error events. | |
Listens for interstitial ad closing events. | |
Removes the listener for interstitial ad closing events. | |
Listens for interstitial ad click events. | |
Removes the listener for interstitial ad click events. | |
Destroys an interstitial ad. | |
Parameter | Type | Mandatory | Description |
|---|---|---|---|
success | function | No | Called when the request to update the user's consent status succeeds. For details, please refer to Parameters in the success callback function. |
fail | function | No | Called when the request to update the user's consent status fails. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
Parameter | Type | Description |
|---|---|---|
consentStatus | number | Consent status.
|
isNeedConsent | boolean | Indicates whether user consent is required.
|
AdProviderList | array | Ad technology provider information list. For details about the AdProvider object structure, please refer to Parameters in AdProvider. |
qg.requestConsentUpdate({
success: function(data) {
console.log('requestConsentUpdate success data ' + JSON.stringify(data))
},
fail: function(data) {
console.log('requestConsentUpdate fail data ' + JSON.stringify(data))
},
complete: function() {},
}) Parameter | Type | Mandatory | Description |
|---|---|---|---|
consentStatus | number | Yes | User consent.
|
qg.setConsentStatus(1)
Parameter | Type | Mandatory | Description |
|---|---|---|---|
childProtection | number | Yes | Indicates whether to process ad requests according to the COPPA.
|
qg.setTagForChildProtection(1)
Sets whether to process ad requests in a manner appropriate for users below the age of consent.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
underAgeOfPromiseStr | number | Yes | Indicates whether to process ad requests in a manner appropriate for users below the age of consent.
|
qg.setTagForUnderAgeOfPromise(1)
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adContentClassification | string | Yes | Ad content rating.
|
qg.setAdContentClassification('W') Parameter | Type | Mandatory | Description |
|---|---|---|---|
personalizedAd | number | Yes | Indicates whether to request non-personalized ads.
|
qg.setNonPersonalizedAd(1)
Creates a native ad component. If a native ad component has been created before, the API returns the existing one.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adUnitId | string | Yes | Native ad unit ID. |
success | function | No | Callback function triggered upon a successful API call. Code 0 indicates success. |
fail | function | No | Callback function triggered upon a failed API call. The failure cause is returned. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
let nativeAd = qg.createNativeAd({
adUnitId: 'xxx',
success: (code) => {
console.log("loadNativeAd loadNativeAd : success");
},
fail: (data, code) => {
console.log("loadNativeAd loadNativeAd fail: " + data + "," + code);
},
complete: () => {
console.log("loadNativeAd loadNativeAd : complete");
}
}); Obtains ad data. On success, the onLoad callback is triggered; on failure, the onError callback is triggered.
Currently, Huawei returns one ad data record each time the API is called.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
channelExtras | Object | No | Extended parameter. For details, please refer to Parameters in channelExtras. |
nativeAd.onLoad((data) => {
console.info('ad data loaded: ' + JSON.stringify(data))
this.adItemData = data.adList[0]
})
nativeAd.load({
"channelExtras": {
"customerChannel": "1"
}
}) Reports ad impressions. Only one report is valid for each ad. adId is a field in the ad data obtained by using the load method.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adId | string | Yes | Ad ID, which is returned in the onload callback. |
nativeAd.reportAdShow({
adId: "xxx"
}) Parameter | Type | Mandatory | Description |
|---|---|---|---|
callback | function | Yes | Function triggered after ad loading is complete. The callback data is an object containing the ad list in form {adList: xxx}. For details, please refer to Parameters in callback. |
Parameter | Type | Description |
|---|---|---|
adList | array | Ad details. For details, please refer to Parameters in item. |
Parameter | Type | Description |
|---|---|---|
adId | string | Ad ID, which is used to report impressions and clicks. |
title | string | Ad title. |
source (1077+) | string | Ad source. |
icon | string | Icon of a promoted app. |
imgUrlList | array | List of image URLs. |
videoUrlList | array | List of video URLs. |
videoRatio(1078+) | array | Ad video aspect ratio. |
logoUrl | string | Ad logo image. NOTE: Currently, Huawei returns only an empty string "". |
clickBtnTxt | string | Text displayed on a clickable button. |
creativeType | number | Ad type.
|
interactionType | number | Interaction type after an ad is clicked.
|
appName | string | App package name. |
versionName | string | App version number. |
developerName | string | App operator information. |
appDetailUrl | string | HTML5 address of the app introduction page. Opening this page via qg.openDeeplink is recommended. |
permissionUrl | string | HTML5 address of the app permission statement page. Opening this page via qg.openDeeplink is recommended. |
privacyUrl | string | Privacy policy URL of the app. Opening this page via qg.openDeeplink is recommended. |
nativeAd.onLoad((data) => {
console.info('ad data loaded: ' + JSON.stringify(data))
this.adItemData = data.adList[0]
}) Parameter | Type | Mandatory | Description |
|---|---|---|---|
callback | function | Yes | Function triggered when an error occurs during ad loading. The callback data is an object containing the result code and message. For details, please refer to Parameters in callback. |
nativeAd.onError((e) => {
console.error('load ad error:' + JSON.stringify(e));
const errCode = e.errCode
const errMsg = e.errMsg
}) nativeAd.offError()
Parameter | Type | Mandatory | Description |
|---|---|---|---|
childProtection | number | Yes | Indicates whether to process ad requests according to the COPPA.
|
nativeAd.setTagForChildProtection(1)
Sets whether to process ad requests in a manner appropriate for users below the age of consent.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
underAgeOfPromiseStr | number | Yes | Indicates whether to process ad requests in a manner appropriate for users below the age of consent.
|
nativeAd.setTagForUnderAgeOfPromise(1)
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adContentClassification | string | Yes | Ad content rating.
|
nativeAd.setAdContentClassification('W') Parameter | Type | Mandatory | Description |
|---|---|---|---|
personalizedAd | number | Yes | Indicates whether to request non-personalized ads.
|
nativeAd.setNonPersonalizedAd(1)
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adId | string | Yes | Ad ID, which is returned in the onload callback. |
Value | Type | Description |
|---|---|---|
0 | number | Call success. |
-1 | number | The method failed due to incorrect parameters. For example, the asset is not an app download ad. |
const resultCode = nativeAd.startDownload({
adId: "xxx"
})
console.log('startDownloadresultCode = ' + resultCode ); Parameter | Type | Mandatory | Description |
|---|---|---|---|
adId | string | Yes | Native ad unit ID, returned in the callback of nativeAd.load(). |
style | Object | Yes | Control button style. For details, please refer to Parameters in style. |
success | function | No | Callback function triggered upon a successful API call. Code 0 indicates success. |
fail | function | No | Callback function triggered upon a failed API call. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
Parameter | Type | Mandatory | Description |
|---|---|---|---|
left | number | Yes | X-coordinate of the control's upper left corner, in pixels. |
top | number | Yes | Y-coordinate of the control's upper left corner, in pixels. |
width | number | No | Control width, in pixels. |
fixedWidth | boolean | No | Indicates whether the control has a fixed width.
The default value is false. |
minWidth | number | No | Minimum control width, in pixels. |
maxWidth | number | No | Maximum control width, in pixels. |
heightType | string | No | Control height.
The default value is normal. |
textSize | number | No | Font size of the text, in pixels. |
font | string | No | Font. |
horizontalPadding | number | No | Left and right padding, in pixels. |
cornerRadius | number | No | Button corner radius, in pixels. |
normalTextColor | string | No | Text color in the normal style, for example, #005BBA. |
normalBackground | string | No | Button background color in the normal style, for example, #0D000000. |
pressedColor | string | No | Button pressed-state color in the normal style, for example, #1A000000. |
normalStroke | number | No | Button stroke width in the normal style, in pixels. |
normalStrokeCorlor | string | No | Button stroke color in the normal style, for example, #0D000000. |
processingTextColor | string | No | Text color in the processing state, for example, #000000. |
processingBackground | string | No | Button background color in the processing state, for example, #00000000. |
processingColor | string | No | Button progress color in the processing state, for example, #33007dff. |
processingStroke | number | No | Button stroke width in the processing state, in pixels. |
processingStrokeCorlor | string | No | Button stroke color in the processing state, for example, #33007dff. |
installingTextColor | string | No | Text color in the installing state, for example, #005BBA. |
installingBackground | string | No | Button background color in the installing state, for example, #0D000000. |
installingStroke | number | No | Button stroke width in the installing state, in pixels. |
installingStrokeCorlor | string | No | Button stroke color in the installing state, for example, #0D000000. |
this.nativeAd.showDownloadButton({
adId : "1**345",
style : {
left:300,
top:500,
heightType:'short',
width:300,
fixedWidth:true,
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");
}
}); Parameter | Type | Mandatory | Description |
|---|---|---|---|
adId | string | Yes | Native ad unit ID, returned in the callback of nativeAd.load(). |
success | function | No | Callback function triggered upon a successful API call. Code 0 indicates success. |
fail | function | No | Callback function triggered upon a failed API call. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
nativeAd.hideDownloadButton({
adId : "1**345",
success: (code) => {
console.log("hideDownloadButton: success");
},
fail: (data, code) => {
console.log(" hideDownloadButton fail: " + data + "," + code);
},
complete: () => {
console.log("hideDownloadButton : complete");
}
}); Creates a rewarded video ad. If an ad with the same adUnitId has already been created, the existing instance will be reused. After creation, the ad assets will be loaded. This API returns a singleton instance that is valid only within the current scene and must not be used across scenes.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adUnitId | string | Yes | ID of a rewarded video ad unit. |
multiton | boolean | No | Indicates whether to enable the multi-instance mode. The default value is false (1077+). |
success | function | No | Callback triggered upon success. Code 0 indicates success. |
fail | function | No | Callback triggered upon failure, which returns the cause of the failure. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
let rewardedVideoAd = qg.createRewardedVideoAd({
adUnitId: 'xxx',
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");
}
}); Manually obtains ads for refreshing the ad content. On success, the onLoad callback is triggered; on failure, the onError callback is triggered.
If requests are sent too frequently, onError may be triggered.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
channelExtras | Object | No | Extended parameter. For details, please refer to Parameters in channelExtras. |
rewardedVideoAd.onLoad(() => {
console.log('ad loaded.')
})
rewardedVideoAd.load({
"channelExtras": {
"customerChannel": "1"
}
}) Displays the rewarded video ad. The rewarded video ad component is hidden by default, and calling show() will make it visible. If the call fails, the onError callback will be triggered.
rewardedVideoAd.onError((e) => {
console.error('load ad error:' + JSON.stringify(e));
const errCode = e.errCode
const errMsg = e.errMsg
})
rewardedVideoAd.show() Parameter | Type | Mandatory | Description |
|---|---|---|---|
callback | function | Yes | Function triggered after ad loading is complete. |
rewardedVideoAd.onLoad(() => {
console.log('ad loaded.')
}) Listens for rewarded video ad closing events. A rewarded video ad can be closed only when the user actively closes it.
Parameter | Type | Description |
|---|---|---|
callback | function | Function triggered after an ad is closed. The callback parameter is {isEnded: xxx}. |
Parameter | Type | Description |
|---|---|---|
isEnded | boolean | Indicates whether a rewarded video ad is closed after being completely watched.
|
rewardedVideoAd.onClose((res) => {
console.log('ad onClose: ' + res.isEnded)
}) Parameter | Type | Mandatory | Description |
|---|---|---|---|
callback | function | Yes | Function triggered when an error occurs during ad loading. The callback data is an object containing the result code and message. |
Parameter | Type | Description |
|---|---|---|
errCode | number | Result code. |
errMsg | string | Message. |
rewardedVideoAd.onError((e) => {
console.error('load ad error:' + JSON.stringify(e));
const errCode = e.errCode
const errMsg = e.errMsg
}) Parameter | Type | Mandatory | Description |
|---|---|---|---|
childProtection | number | Yes | Indicates whether to process ad requests according to the COPPA.
|
rewardedVideoAd.setTagForChildProtection(1)
Sets whether to process ad requests in a manner appropriate for users below the age of consent.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
underAgeOfPromiseStr | number | Yes | Indicates whether to process ad requests in a manner appropriate for users below the age of consent.
|
rewardedVideoAd.setTagForUnderAgeOfPromise(1)
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adContentClassification | string | Yes | Ad content rating.
|
rewardedVideoAd.setAdContentClassification('W') Parameter | Type | Mandatory | Description |
|---|---|---|---|
personalizedAd | number | Yes | Indicates whether to request non-personalized ads.
|
rewardedVideoAd.setNonPersonalizedAd(1)
Creates a banner ad component. If a banner ad component has been created before, the API returns the existing one.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adUnitId | string | Yes | Banner ad unit ID. |
style | object | Yes | Style of the banner ad component. For details, please refer to Parameters in style. |
adIntervals | number | No | Interval for automatically refreshing an ad, in seconds. The value ranges from 30 to 120. The recommended value is 60. If this parameter is not passed, banner ads will not be automatically refreshed. This parameter is valid only when the API is called for the first time. If this parameter is not set for the first time, the setting is invalid in subsequent calls. The setting is valid only when the ad is re-created after the bannerAd.destroy() API is called to destroy the ad. |
Parameter | Type | Mandatory | Description |
|---|---|---|---|
top | number | Yes | Y coordinate of the upper left corner of the banner ad component. |
left | number | Yes | X coordinate of the upper left corner of the banner ad component. |
width | number | Yes | Width of the banner ad component, in dp. |
height | number | Yes | Height of the banner ad component, in dp. |
The following table describes the restrictions on the width and height of the ad component.
Width | Height | Description |
|---|---|---|
360 | 57 | Regular banner ads, applicable to 1080 x 170 px ad assets. |
360 | 144 | Large banner ads, applicable to 1080 x 432 px ad assets. |
160 | 600 | Not supported in the Chinese mainland. |
300 | 250 | Not supported in the Chinese mainland. |
320 | 100 | Not supported in the Chinese mainland. |
320 | 50 | Not supported in the Chinese mainland. |
468 | 60 | Not supported in the Chinese mainland. |
728 | 90 | Not supported in the Chinese mainland. |
-1 | -2 | The ad width and height automatically adapt to the screen size. |
Banner ad component bannerAd. You can use bannerAd.style to obtain the actual width and height of an ad. The returns are described as follows.
Parameter | Type | Description |
|---|---|---|
top | number | Y coordinate of the upper left corner of the banner ad component. |
left | number | X coordinate of the upper left corner of the banner ad component. |
width | number | Width of the banner ad component, in dp. |
height | number | Height of the banner ad component, in dp. |
realWidth | number | Actual width of the banner ad component, in pixels. |
realHeight | number | Actual height of the banner ad component, in pixels. |
let bannerAd = qg.createBannerAd({
adUnitId: 'testw6vs28auh3',
style:{
top:20,
left:20,
height:57,
width:360
}
}) Loads and displays a banner ad. When an error occurs, onError is triggered. When the loading is successful, onLoad is triggered.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
channelExtras | Object | No | Extended parameter. For details, please refer to Parameters in channelExtras. |
bannerAd.show({
"channelExtras": {
"customerChannel": "1"
}
}) Parameter | Type | Mandatory | Description |
|---|---|---|---|
errMsg | string | Yes | Message. |
errCode | number | Yes | Result code. |
bannerAd.onError((err)=>{
console.log(err)
}) Creates an interstitial ad component. If an interstitial ad component has been created before, the API returns the existing one.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
adUnitId | String | Yes | Interstitial ad unit ID. |
let interstitialAd = qg.createInterstitialAd({
adUnitId: 'xxxx'
}) Parameter | Type | Mandatory | Description |
|---|---|---|---|
channelExtras | Object | No | Extended parameter. For details, please refer to Parameters in channelExtras. |
interstitialAd.load({
"channelExtras": {
"customerChannel": "1"
}
}) interstitialAd.onLoad(function (data) {
console.log('onLoad data ' + JSON.stringify(data));
}); Parameter | Type | Description |
|---|---|---|
errMsg | string | Message. |
errCode | number | Result code. |
interstitialAd.onError((err)=>{
console.log(err)
}) interstitialAd.onClose(()=>{
console.log('interstitialAd closed');
}) interstitialAd.onClick(()=>{
console.log('interstitialAd clicked');
}) A result code is the information obtained through the onError method.
Result Code | Description |
|---|---|
200 | Universal error. |
202 | Invalid parameter. |
1001 | The ad request is invalid due to specific reasons. For example, the ad unit ID is not set or the banner ad dimensions are invalid. |
1002 | The banner ad has expired or the banner ad task has been removed. |
1003 | Internal error. |
1004 | The ad request succeeded, but the server did not return any available ad assets. |
1100 | The ad is being requested and cannot be requested again. |
1102 | The API version is not supported by Ads Kit. |
1104 | The ad request failed due to a network connection error. |
2000 | The HMS Core (APK) version is outdated, which does not support the setting of AppInfo. |