# Advertising
# createInterstitialAd
Supported from Base Library 3.5.4 onwards
createInterstitialAd(Object object)
Creates an interstitial ad component and returns an InterstitialAd instance.
Parameters
Object object
| Attribute | Type | Default Value | Required | Description |
|---|---|---|---|---|
| adUnitId | string | Yes | Ad ID | |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for API call completion (executed on both success and failure) |
# InterstitialAd
# InterstitialAd.show()
Displays the interstitial ad and returns a Promise.
# InterstitialAd.load()
Loads the interstitial ad and returns a Promise.
# InterstitialAd.destroy()
Destroys the interstitial ad instance.
# InterstitialAd.onLoad
Accepts a function as a parameter and listens for the interstitial ad load event.
# InterstitialAd.offLoad
Removes the listener function for the interstitial ad load event. If no parameter is passed, all listeners are removed.
# InterstitialAd.onError
Accepts a function as a parameter and listens for the interstitial ad error event.
# InterstitialAd.offError
Removes the listener function for the interstitial ad error event. If no parameter is passed, all listeners are removed.
# InterstitialAd.onClose
Accepts a function as a parameter and listens for the interstitial ad close event.
# InterstitialAd.offClose
Removes the listener function for the interstitial ad close event. If no parameter is passed, all listeners are removed.
# createRewardedVideoAd
Supported from Base Library 3.5.4 onwards
createRewardedVideoAd(Object object)
Creates an interstitial ad component and returns a RewardedVideoAd instance.
Parameters
Object object
| Attribute | Type | Default Value | Required | Description |
|---|---|---|---|---|
| adUnitId | string | Yes | Ad ID | |
| success | function | No | Callback function for successful API call | |
| fail | function | No | Callback function for failed API call | |
| complete | function | No | Callback function for API call completion (executed on both success and failure) |
# RewardedVideoAd
# RewardedVideoAd.show()
Displays the interstitial ad and returns a Promise.
# RewardedVideoAd.load()
Loads the interstitial ad and returns a Promise.
# RewardedVideoAd.destroy()
Destroys the interstitial ad instance.
# RewardedVideoAd.onLoad
Accepts a function as a parameter and listens for the interstitial ad load event.
# RewardedVideoAd.offLoad
Removes the listener function for the interstitial ad load event. If no parameter is passed, all listeners are removed.
# RewardedVideoAd.onError
Accepts a function as a parameter and listens for the interstitial ad error event.
# RewardedVideoAd.offError
Removes the listener function for the interstitial ad error event. If no parameter is passed, all listeners are removed.
# RewardedVideoAd.onClose
Accepts a function as a parameter and listens for the interstitial ad close event.
# RewardedVideoAd.offClose
Removes the listener function for the interstitial ad close event. If no parameter is passed, all listeners are removed.
# APP Implementation of Custom Ad Flow
# 0. SDK Default Implementation
Note: Built-in ad implementation is supported from Base Library 3.12.5 and SDK 2.53.9 onwards. For details, refer to Ad Management;
# 1. Implement the invokeNativeAd Custom API
The create method of the ad internally calls the invokeNativeAd API. Therefore, the APP needs to implement a custom API with the same name.
Implementation method for custom APIs:
iOS Implementation Method (opens new window)
Android Implementation Method (opens new window)
# 2. After Receiving the invokeNativeAd Call, the APP Handles Different Types Based on Parameters (Handling show, load, destroy)
The invokeNativeAd API parameters received by the APP include the following fields:
| Attribute | Type | Default Value | Description |
|---|---|---|---|
| type | string | Ad ID, the value is either InterstitialAd or RewardedVideoAd | |
| method | string | The method called by the ad, the value is one of create, show, load, destroy, corresponding to the methods of the Mini-Program's ad instance | |
| adUnitId | string | The ad ID passed during create | |
| instanceId | string | The unique instance ID generated during create |
The APP can handle different processing based on the parameters.
# 3. The APP Triggers onLoad, onClose, onError Logic Based on the Ad Display Flow
When triggering, events need to be sent to the Mini-Program via the SDK. Example parameters are as follows:
{
name: 'onNativeAdEvent', // Required, onNativeAdEvent indicates an ad callback event
data: {
method: 'onLoad', // Required, indicates the ad callback event. Valid values are onLoad, onError, onClose
adUnitId: '', // Optional, indicates the ad ID
instanceId: 'xxx', // Required, the instance ID passed during create
}
}
Methods for sending custom events: