目录

NativeAd

Overview

Native ad object.

Methods

Method

Description

Parameter

Return Value

load()

Loads an ad.

-

-

setRequestConfig(object)

Sets ad request parameters.

For details about ad parameters applicable to all ad units, please refer to RequestConfig.

-

onLoad(callback)

Listens to ad loading success.

callback: callback for ad loading success.

Parameter in callback: Array<AdData>

Promise<Array<AdData>>: data that is returned when an ad is successfully loaded.

offLoad()

Cancels listening to ad loading success.

-

-

onError(callback)

Listens to ad loading failure.

callback: callback for ad loading failure, which carries the error code.

Parameter in callback: errorcode

-

offError()

Cancels listening to ad loading failure.

-

-

reportAdShow(object)

Reports an ad impression.

CAUTION:

1. Submit a ticket or send an email to petalads@huawei.com to apply to the traffic operations staff for enabling the capability.

2. Sign in to Petal Publisher Center, click My apps in the navigation tree on the left, find your app, and click Settings in the Operation column. On the page displayed, add the corresponding domain name to Domain name trustlist.

adId: ID of an ad asset.

-

reportAdClick(object)

Reports an ad click event.

CAUTION:

1. Submit a ticket or send an email to petalads@huawei.com to apply to the traffic operations staff for enabling the capability.

2. Sign in to Petal Publisher Center, click My apps in the navigation tree on the left, find your app, and click Settings in the Operation column. On the page displayed, add the corresponding domain name to Domain name trustlist.

  • adId: ID of an ad asset.
  • (Optional) clickX: horizontal coordinate of the click position relative to the ad unit. Value type: int; value unit: px; example: 10
  • (Optional) clickY: vertical coordinate of the click position relative to the ad unit. Value type: int; value unit: px; example: 10
  • (Optional) clickDTime: number // Timestamp upon a click (accurate to milliseconds), for example, 1710311431611.
  • (Optional) clickUTime: number // Timestamp upon a click release (accurate to milliseconds), for example, 1710311431892.
  • (Optional) creativeSize: ad unit dimensions (width x height). Value type: string; value unit: px; example: 360 x 160

Note: You can pass clickX, clickY, and creativeSize to data, which helps traffic monetization.

-

reportAdClose(object)

Reports an ad closure event.

  • adId: ID of an ad asset.
  • (Optional) keyWords (in string[]): reason why an ad is closed.

-

onAdClick(object)

Called when a user is redirected to a landing page after clicking the ad.

  • adId: ID of an ad asset.
  • (Optional) clickX: horizontal coordinate of the click position relative to the ad unit. Value type: int; value unit: px; example: 10
  • (Optional) clickY: vertical coordinate of the click position relative to the ad unit. Value type: int; value unit: px; example: 10
  • (Optional) clickDTime: number // Timestamp upon a click (accurate to milliseconds), for example, 1710311431611.
  • (Optional) clickUTime: number // Timestamp upon a click release (accurate to milliseconds), for example, 1710311431892.
  • (Optional) creativeSize: ad unit dimensions (width x height). Value type: string; value unit: px; example: 360 x 160

Note: You can pass clickX, clickY, and creativeSize to data, which helps traffic monetization.

-

gotoWhyThisAdPage(object)

Goes to the page explaining why an ad is displayed.

adId: ID of an ad asset.

-

startDownload(object)

Starts app download.

CAUTION:

1. Submit a ticket or send an email to petalads@huawei.com to apply to the traffic operations staff for enabling the capability.

2. Sign in to Petal Publisher Center, click My apps in the navigation tree on the left, find your app, and click Settings in the Operation column. On the page displayed, add the corresponding domain name to Domain name trustlist.

adId: ID of an ad asset.

Promise<number>: indicates whether the download is successful.

Options of number:

  • 0: Download succeeded.
  • -1: Download failed due to a parameter error.
  • -2: No download permission.

resumeDownload(object)

Resumes app download.

adId: ID of an ad asset.

Promise<number>: indicates whether the download is successful after resumption.

Options of number:

  • 0: Download succeeded.
  • -1: Download failed due to a parameter error.
  • -2: No download permission.

pauseDownload(object)

Pauses app download.

adId: ID of an ad asset.

-

cancelDownload(object)

Cancels app download.

adId: ID of an ad asset.

-

getDownloadProgress(object)

Obtains the app download progress.

adId: ID of an ad asset.

Promise<number>: current download progress.

Value range of number: [0,100]

getAppStatus(object)

Obtains the app status.

adId: ID of an ad asset.

Promise<string>

The options are as follows:

  • DOWNLOAD: App download has not started. This is the initial download status.
  • DOWNLOADING: The app is being downloaded.
  • DOWNLOADFAILED: App download failed.
  • WAITING: Waiting for app download.
  • PAUSE: App download is paused.
  • INSTALL: Waiting for app installation.
  • INSTALLING: The app is being installed.
  • INSTALLED: App installation is complete. The app can be launched.

onStatusChanged(callback)

Listens to download status changes.

callback: callback for download status changes.

Parameters in callback: packageName and status

-

offStatusChanged()

Cancels listening to download status changes.

-

-

onDownloadProgress(callback)

Listens for download progress changes.

callback: callback for download progress changes.

Parameters in callback: packageName and progress

-

offDownloadProgress()

Cancels listening to download progress changes.

-

-

destroy()

Destroys an ad object.

-

-

showPrivacyPolicy(object: Object)

Launches the browser to show the privacy policy page.

adId: ID of an ad asset.

  

showAppDetailPage(object: Object)

Shows the app details page.

adId: ID of an ad asset.

  

showPermissionPage(object: Object)

Launches the browser to show the app permission page.

adId: ID of an ad asset.

  

onUserCancel(callback: (ret: Object)

Listens to download cancellation status changes.

callback: callback for download cancellation status changes. Parameters of the callback are packageName and uniqueId.

  

offUserCancel()

Cancels listening to download cancellation status changes.

     

showPrivacyPolicyInWeb(object: Object)

Shows the privacy policy page using WebView.

adId: ID of an ad asset.

  

showPermissionPageInWeb(object: Object)

Shows the app permission page using WebView.

adId: ID of an ad asset.

  

onAppOpen(callback: (ret: Object)

Listens to app launches.

callback: callback for download status changes.

Parameters of the callback are packageName, status, and uniqueId.

  

offAppOpen()

Cancels listening to app launches.

     

showTransparencyDialog(object: Object,rect: DOMRect, theme: number)

Shows the ad transparency dialog box.

1. adId: ID of an ad asset.

2. rect: coordinates of the click point.

The options are as follows:

  • bottom: number
  • height: number
  • left: number
  • right: number
  • top: number
  • width: number
  • x: number
  • y: number
  • 3: theme
  • 0: light color mode (default)
  • 1: dark mode
  

dismissTransparencyDialog()

Destroys the ad transparency dialog box.

     

[h2]AdData

Attribute

Type

Description

adId

String

ID of an ad asset.

adType

number

Ad type.

app

AppInfo

Advertised app.

clickBtnTxt

String

Text to be displayed on an ad interaction button, for example, View details or Install.

creativeType

number

Ad creative type. For details, please refer to CreativeType and Mapping Between DetailedCreativeType and CreativeType.

desc

String

Ad description.

imgList

Array<ImageInfo>

Ad images.

interactionType

number

Ad purpose.

  • 0: for display only
  • 1: web page promotion
  • 2: app download
  • 3: app/quick app engagement
  • 4: quick app promotion (not supported by the Petal Ads JavaScript API currently)
  • 5: app promotion

keywords

Array<string>

Reason why an ad is disliked.

source

String

Ad source.

title

String

Ad title.

video

VideoInfo

Video ad asset.

slotId

String

Ad unit ID.

showAppElement

number

Indicates whether to show app elements for delivery from the server.

transparencyOpen

string

Indicates whether ad transparency information is displayed.

promoteInfo

PromoteInfo

Information about the promoted entity.

abilityInfo

string

HarmonyOS FA.

[h2]AppInfo

Attribute

Type

Description

appName

String

App name.

appDesc

String

App description.

iconUrl

String

App icon URL.

packageName

String

App package name.

privacyLink

String

Privacy link.

permissionUrl

String

HTML5 address of the app permission declaration page.

appDetailUrl

String

HTML5 address of the app details page.

versionName

String

App version number (similar to 4.52.0).

developerName

String

App developer information.

[h2]ImageInfo

Attribute

Type

Description

width

number

Image width, in pixels.

height

number

Image height, in pixels.

imageType

string

Image type.

  • img
  • gif

url

String

Image URL.

[h2]VideoInfo

Attribute

Type

Description

duration

Integer

Playback duration of a video file, in milliseconds.

ratio

Float

Video aspect ratio.

fileSize

Integer

Video file size, in bytes.

url

String

Video URL.

[h2]PromoteInfo

Attribute

Type

Description

type

number

Promotion subtype.

  1. Quick app.
  2. WeChat mini-program.

name

string

Name of the promoted entity. The value is URL-encoded. Your app needs to decode it before using it.