目录

Advertising

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.

This document describes only the API definition. For details about the API usage sequence and scenarios, please refer to Advertising and Integrating AGD Pro.

API Declaration

Add the following configuration to the features attribute in the manifest.json file:

{"name": "service.ad"}

Modules to Import

Add the following configuration to the script element on the API call page:

import ad from '@service.ad'

or

var ad = require("@service.ad")

Restrictions

Item

Description

Applicable Device

Mobile phones and tablets

Applicable Region

Global

Definition

API

Description

ad.getProvider()

Obtains the service provider information, for example, the English brand name of the vendor.

Rewarded video ad APIs

ad.createRewardedVideoAd(Object object) (1075+)

Creates a rewarded video ad.

rewardedVideoAd.load()

Manually obtains ads for refreshing the ad content.

rewardedVideoAd.show()

Displays the rewarded video ad. The rewarded video ad is hidden by default, and calling show() will make it visible.

rewardedVideoAd.onLoad(function callback)

Sets the callback for successful ad loading.

rewardedVideoAd.offLoad()

Removes the listener for successful rewarded video ad loading.

rewardedVideoAd.onClose(function callback)

Listens for rewarded video ad closing events. A rewarded video ad can be closed only when the user actively closes it.

rewardedVideoAd.offClose()

Removes the listener for rewarded video ad closing events.

rewardedVideoAd.onError(function callback)

Listens for rewarded video ad loading error events.

rewardedVideoAd.offError()

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.

rewardedVideoAd.setNonPersonalizedAd(number personalizedAd)

Sets whether to request non-personalized ads.

rewardedVideoAd.destroy()

Destroys a rewarded video ad.

Banner ad APIs

ad.createBannerAd(Object object) (1078+)

Creates a banner ad. If a banner ad has been created before, the API returns the existing one.

bannerAd.show()

Loads and displays a banner ad.

bannerAd.hide()

Hides a banner ad.

bannerAd.onError(function callback)

Listens for banner ad error events.

bannerAd.offError()

Removes the listener for banner ad error events.

bannerAd.onLoad(function callback)

Listens for banner ad loading events.

bannerAd.offLoad()

Removes the listener for banner ad loading events.

bannerAd.onClose(function callback)

Listens for banner ad closing events.

bannerAd.offClose()

Removes the listener for banner ad closing events.

bannerAd.destroy()

Destroys a banner ad.

Interstitial ad APIs

ad.createInterstitialAd(Object object) (1078+)

Creates an interstitial ad.

interstitialAd.load()

Loads an interstitial ad.

interstitialAd.show()

Displays an interstitial ad.

interstitialAd.onLoad(function callback)

Listens for interstitial ad loading events.

interstitialAd.offLoad()

Removes the listener for interstitial ad loading events.

interstitialAd.onError(function callback)

Listens for interstitial ad error events.

interstitialAd.offError()

Removes the listener for interstitial ad error events.

interstitialAd.onClose(function callback)

Listens for interstitial ad closing events.

interstitialAd.offClose()

Removes the listener for interstitial ad closing events.

interstitialAd.onClick(function callback)

Listens for interstitial ad click events.

interstitialAd.offClick()

Removes the listener for interstitial ad click events.

interstitialAd.destroy()

Destroys an interstitial ad.

[h2]ad.getProvider() (1075+)

[h2]ad.createRewardedVideoAd(Object object) (1075+)

[h2]rewardedVideoAd.load() (1075+)

If requests are sent too frequently, onError may be triggered.

[h2]rewardedVideoAd.show() (1075+)

[h2]rewardedVideoAd.onLoad(function callback) (1075+)

[h2]rewardedVideoAd.offLoad() (1075+)

[h2]rewardedVideoAd.onClose(function callback) (1075+)

[h2]rewardedVideoAd.offClose() (1075+)

[h2]rewardedVideoAd.onError(function callback) (1075+)

[h2]rewardedVideoAd.offError() (1075+)

[h2]rewardedVideoAd.setTagForChildProtection(number childProtection) (1077+)

[h2]rewardedVideoAd.setTagForUnderAgeOfPromise(number underAgeOfPromiseStr) (1077+)

[h2]rewardedVideoAd.setAdContentClassification(string adContentClassification) (1077+)

[h2]rewardedVideoAd.setNonPersonalizedAd(number personalizedAd) (1077+)

[h2]rewardedVideoAd.destroy() (1075+)

[h2]ad.createBannerAd(Object object) (1078+)

[h2]bannerAd.show() (1078+)

[h2]bannerAd.hide() (1078+)

[h2]bannerAd.onError(function callback) (1078+)

[h2]bannerAd.offError() (1078+)

[h2]bannerAd.onLoad(function callback) (1078+)

[h2]bannerAd.offLoad() (1078+)

[h2]bannerAd.onClose(function callback) (1078+)

[h2]bannerAd.offClose() (1078+)

[h2]bannerAd.destroy() (1078+)

[h2]ad.createInterstitialAd(Object object) (1078+)

[h2]interstitialAd.load() (1078+)

[h2]interstitialAd.show() (1078+)

[h2]interstitialAd.onLoad(function callback) (1078+)

[h2]interstitialAd.offLoad() (1078+)

[h2]interstitialAd.onError(function callback) (1078+)

[h2]interstitialAd.offError() (1078+)

[h2]interstitialAd.onClose(function callback) (1078+)

[h2]interstitialAd.offClose() (1078+)

[h2]interstitialAd.onClick(function callback) (1078+)

[h2]interstitialAd.offClick() (1078+)

[h2]interstitialAd.destroy() (1078+)

Result Codes

A result code is the error 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.