使用UNI-APP開發廣告類型的小程序

1.插屏廣告javascript

// 在頁面中定義插屏廣告
let interstitialAd = null

// 在頁面onLoad回調事件中建立插屏廣告實例
if (wx.createInterstitialAd) {
  interstitialAd = wx.createInterstitialAd({
    adUnitId: '本身的廣告id'
  })
  interstitialAd.onLoad(() => {})
  interstitialAd.onError((err) => {})
  interstitialAd.onClose(() => {
})
} // 在適合的場景顯示插屏廣告 if (interstitialAd) { interstitialAd.show().catch((err) => { console.error(err) }) }

2.視頻或banner廣告java

<ad unit-id="" ad-type="video" ad-theme="white"></ad>
<ad unit-id="" ad-type="banner" ad-theme="white"></ad>

3.激勵視頻ide

// 在頁面中定義激勵視頻廣告
let videoAd = null

// 在頁面onLoad回調事件中建立激勵視頻廣告實例
if (wx.createRewardedVideoAd) {
  videoAd = wx.createRewardedVideoAd({
    adUnitId: ''
  })
  videoAd.onLoad(() => {})
  videoAd.onError((err) => {})
  videoAd.onClose((res) => {})
}

// 用戶觸發廣告後,顯示激勵視頻廣告
if (videoAd) {
  videoAd.show().catch(() => {
    // 失敗重試
    videoAd.load()
      .then(() => videoAd.show())
      .catch(err => {
        console.log('激勵視頻 廣告顯示失敗')
      })
  })
}

4.視頻貼片廣告視頻

<video unit-id=""></video>

5。原生模板廣告blog

<ad-custom unit-id=""></ad-custom>
相關文章
相關標籤/搜索