小程序 · 3种广告

1. Banner广告

<div class="margin-xs padding-xs radius bg-white">
    <ad unit-id="adunit-91f767d951338851" class="radius"></ad>
  </div>
复制代码

2. 插屏广告

data() {
  return {
    interstitialAd: null
  }
},
onLoad() {

  // 在页面onLoad回调事件中建立插屏广告实例
  if (wx.createInterstitialAd) {
    console.log('wx.createInterstitialAd')
    this.interstitialAd = wx.createInterstitialAd({
      adUnitId: 'adunit-7487758745f99b14'
    })
  }

  if (this.interstitialAd) {
    this.interstitialAd.show().catch((err) => {
      console.error(err)
    })
  }
  
},
复制代码

3. 激励视频广告

data() {
  return {
    videoAd: null
  }
},
onLoad() {

  // 在页面onLoad回调事件中建立激励视频广告实例
  if (wx.createRewardedVideoAd) {
    this.videoAd = wx.createRewardedVideoAd({
      adUnitId: 'adunit-296656170310d2cd'
    })
  }

  // 用户触发广告后,显示激励视频广告
  if (this.videoAd) {
    this.videoAd.show().catch(() => {
      // 失败重试
      this.videoAd.load()
        .then(() => this.videoAd.show())
        .catch(err => {
          console.log('激励视频 广告显示失败')
        })
    })
  }

},
复制代码
相关文章
相关标签/搜索