# Motivational Video Advertising
Mini Program advertising traffic main operating guidelines:Document address
The incentive video advertising component is composed of client-side native image, text, and video controls, which are the highest level and will be overlaid on the common components.
Developers can call wx.createRewardedVideoAd Create Motivational Video Advertising Components. The method returns a singleton,This instance is valid only for the current page and is not allowed across pages.
# Advertising creation
The Incentive Video Ads component is hidden by default, so it can be created in advance to initialize the component in advance. The developer can view the Mini Program page on the onLoad Event callback and invoke the ad instance repeatedly over the life of the page.
let rewardedVideoAd = null
Page({
onLoad() {
if(wx.createRewardedVideoAd){
rewardedVideoAd = wx.createRewardedVideoAd({ adUnitId: 'xxxx' })
rewardedVideoAd.onLoad(() => {
console.log('onLoad event emit' )
})
rewardedVideoAd.onError((err) => {
console.log('onError event emitting, err)
})
rewardedVideoAd.onClose((res) => {
console.log('onClose event emitting, res)
})
}
}
})
In order to avoid the abuse of advertising resources, the current number of times each user can watch incentive video ads per day is limited, it is recommended to judge whether the ad is successful before displaying the ad button.
# display/hide
The incentive video ad component is hidden by default. After the user actively triggers the ad, the developer needs to call RewardedVideoAd.show() For display.
rewardedVideoAd.show()
Only after the user clicks on the incentive video ad component on the Close Advertising
Button, the ad will close. Developers have no control over the hiding of incentive video advertising components.
# Advertising Success and Failure
The Incentive Video Ad component automatically pulls and updates ads. The ad is pulled once after the component is created, and the user clicks Close Advertising
Then I'll take down the next advertisement.
If the pull is successful, pass the RewardedVideoAd.onLoad() The registered callback function will execute,RewardedVideoAd.show() Returned Promise Will also be a resolved Promise。Both callbacks have no parameter passing.
rewardedVideoAd.onLoad(() => {
console.log('InspirationVideo Ad Loaded Successfully ')
})
rewardedVideoAd.show()
.then(() => console.log('InspirationVideo Advertising'))
If the pull fails, pass the RewardedVideoAd.onError() The registered callback function is executed with an object containing an error message as its argument.Common Exception Errors Reference Document
rewardedVideoAd.onError(err => {
console.log(err)
})
RewardedVideoAd.show() Returned Promise Will also be a rejected Promise。
rewardedVideoAd.show()
.catch(err => console.log(err))
# Pull failed, pull again
If an automatic pull of a component fails, then the show() Will be reject。At this point you can call RewardedVideoAd.load() Manually re-pull the ad.
rewardedVideoAd.show()
.catch(() => {
rewardedVideoAd.load()
.then(() => rewardedVideoAd.show())
.catch(err => {
console.log('InspirationVideo Advertisement display failure')
})
})
If the automatic pull of the component is successful, the call load() The method will directly return a resolved Promise without advertising.
rewardedVideoAd.load()
.then(() => rewardedVideoAd.show())
# Listening to users turn off ads
Only after the user clicks on the incentive video ad component on the Close Advertising
Button, the ad will close. This event can be accessed through RewardedVideoAd.onClose() Listening.
RewardedVideoAd.onClose() The callback function will pass in a parameter res,res.isEnded
Describe the state of the ad when it is turned off.
attribute | type | Introductions |
---|---|---|
isEnded | boolean | Whether the video is turned off while the user is watching it in full, true Indicates that the user is closing the video after the video frequency is played, false Indicates that the user turned off the video during the video playback |
Developers are required to res.isEnded
Determine whether the video is played to end, you can issue a reward to the user.
rewardedVideoAd.onClose(res => {
// The user clicked the [Close Ads] button
if (res && res.isEnded) {
// Normal play ends, you can issue game rewards
} else {
// Play out midway, do not issue game rewards
}
})
# Note
Multiple calls RewardedVideoAd.onLoad()、RewardedVideoAd.onError()、RewardedVideoAd.onClose() Methods such as monitoring ad events will produce multiple event callbacks, it is recommended to monitor once after creating an ad, or cancel the original monitoring event and then re-monitor.