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

WeChat small program ads and video ads


May 18, 2021 WeChat Mini Program Development Document


Table of contents


Post an ad in front of the video

Small program ad traffic master action guide: document address

Developers can add property configurations to the video component, create a small program video pre-ad component, video ad component will automatically pull ad data after creation, video display ads before playback.

Ad style

The presentation style is centered vertically or horizontally in the video component set by the developer at a scale of 16:9

Ad creation

The following ad-related property configurations have been added to the video component, and ads can be displayed when ad-unit-id is set

Property Type The default Required Description
ad-unit-id string Is Ad unit id, which can be created in the main module of traffic behind the scenes for small program management
bindadload eventhandle Whether The ad loads a successful callback
bindaderror eventhandle Whether The ad load fails with a callback, returning the code with the ad component
bindadclose eventhandle Whether Callbacks for ad shutdown
bindadplay eventhandle Whether The ad starts and ends the playback of the callback event.detail . . . type: 'begin/end'.

Add ad units to bind ad events

<video 
  class="xxx"
  src="xxx"
  bindadplay="onAdplay"
  bindadload="onAdload"
  bindadclose="onAdclose"
  bindaderror="onAdError"
  ad-unit-id="xxx"
>
</video>

Listen for ad events

Page({
  onAdplay(e) {
    console.log('onAdplay', e)
  },
  onAdload(e){
    console.log('onAdload', e)
  },
  onAdclose(e) {
    console.log('onAdclose', e)
  },
  onAdError(e) {
    console.log('onAdError', e)
  },
})

Ads are preloaded

Developers can call wx.preloadVideoAd to preload ads


const adUnitId1 = 'xxx'
const adUnitId2 = 'xxx'
wx.preloadVideoAd([adUnitId1, adUnitId2])

Error code

The error code is an error message obtained through the bindaderror callback, and the following error code has been added to the previous ad and then the normal ad component ad error code.

Code Abnormal condition Solution
3001 Hit frequency control strategy Treat by no ads
3002 Hit frequency control strategy Treat by no ads
3003 Hit frequency control strategy Treat by no ads
3004 Hit frequency control strategy Treat by no ads

Precautions

1, support video preloading capacity: document address.

2. Only video components in the same layer rendering mode are supported.

3, developers can listen to bindadplay events to get the status of advertising playback, to make appropriate treatment.

4, ad-unit-id does not support asynchronous settings, only set in wxml or js file data properties, set data settings are not valid.

5, full-screen mode does not show the video before posting ads.