Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program advertising and motivation video advertising


May 18, 2021 WeChat Mini Program Development Document


Table of contents


Motivate video ads

Small program ad traffic master action guide: document address

The incentive video ad component is composed of the client's native image, text, and video controls, with the highest level and coverage on the normal component.

Developers can call wx.createRewardedVideoAd to create an incentive video ad component. The method returns a single instance that is valid only for the current page and is not allowed to be used across pages.

Ad creation

The incentive video ad component is hidden by default, so it can be created in advance to initialize the component. Developers can create an ad instance in the onLoad event callback for a small program page and repeatedly call the ad instance 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 emit', err)
      })
      rewardedVideoAd.onClose((res) => {
        console.log('onClose event emit', res)
      })
    }
  }
})

To avoid abusing ad resources, each user can currently watch incentive video ads a limited number of times per day, it is recommended to show the ad button before judging whether the ad pull success.

Show/Hide

The incentive video ad component is hidden by default, and developers need to call RewardedVideoAd.show() to display it after the user actively triggers the ad.

rewardedVideoAd.show() 

Ads close only when a user clicks the Close Ads button on the Incentive Video ad component. Developers have no control over the hidden incentive video ad components.

Ads pull success and failure

The Incentive Video Ad component automatically pulls ads and updates them. Once the component is created, an ad is pulled, and when the user clicks Close the ad, they pull the next ad.

If the pull is successful, the callback function registered by RewardedVideoAd.onLoad () will be executed, and the promise returned by RewardedVideoAd.show () will also be a resolved promise.There are no parameters pass in the callback function of both.

rewardedVideoAd.onLoad(() => {
  console.log('激励视频 广告加载成功')
})

rewardedVideoAd.show()
.then(() => console.log('激励视频 广告显示'))

If the pull fails, the callback function registered by RewardedVideoAd.onError () will execute, the parameter of the callback function is an object containing the error message.

rewardedVideoAd.onError(err => {
  console.log(err)
})

RewardedVideoAd.show () The promise returned will also be a Rejected Promise.

rewardedVideoAd.show()
.catch(err => console.log(err))

Pulling failure, re-draw

If one of the component's automatic pulls fails, the show() that is called later will be rejected. At this point, you can call RewardedVideoAd.load() to manually re-pull the ad.

rewardedVideoAd.show()
.catch(() => {
    rewardedVideoAd.load()
    .then(() => rewardedVideoAd.show())
    .catch(err => {
      console.log('激励视频 广告显示失败')
    })
})

If the component's automatic pull is successful, calling the load() method returns a resolved Promise directly, not an ad.

rewardedVideoAd.load()
.then(() => rewardedVideoAd.show())

Listen to users turn off ads

Ads close only when a user clicks the Close Ads button on the Incentive Video ad component. This event can be monitored through RewardedVideoAd.onClose().

WeChat small program advertising and motivation video advertising

The callback function of RewardedVideoAd.onClose() passs in an argument res.isEnded describes the status of the ad when it is turned off.

Property Type Description
isEnded boolean Whether the video is turned off while the user is watching in its entirety, true indicates that the user closes the video after the video is played, false indicates that the user turned off the video while the video is playing

Developers need to use res.isEnded to determine if the video ends and can send a reward to the user.

rewardedVideoAd.onClose(res => {
    // 用户点击了【关闭广告】按钮
    if (res && res.isEnded) {
      // 正常播放结束,可以下发游戏奖励
    } else {
      // 播放中途退出,不下发游戏奖励
    }
})

Precautions

Multiple calls to RewardedVideoAd.onLoad (), RewardedVideoAd.onError (), RewardedVideoAd.onClose() and other methods to listen to an ad event will result in multiple event callbacks, suggesting that you can listen once after you create an ad, or cancel the original listening event before re-listening.