微信小程序 廣告·原生模板廣告

2022-04-27 11:24 更新

原生模板 廣告

小程序廣告流量主操作指引:文檔地址

開發(fā)者可以使用 ad-custom 組件創(chuàng)建 原生模板 廣告組件,原生模板 廣告組件在創(chuàng)建后會自動拉取廣告數(shù)據(jù)并顯示。

廣告尺寸設(shè)置

原生模板 廣告不允許直接設(shè)置樣式屬性,默認(rèn)寬度為100%(width: 100%),高度會自動等比例計(jì)算,因此開發(fā)者可以設(shè)置廣告外層組件的寬度調(diào)整廣告的尺寸。 廣告外層組件的寬度和具體模板相關(guān),具體可以參考模板編輯器文檔。

/* 外層組件的寬度可設(shè)置成100%或具體數(shù)值 */
.adContainer {
  width: 100%;
}
<view class="adContainer">
  <ad-custom unit-id="xxxx"></ad-custom>
</view>

廣告事件監(jiān)聽

原生模板 廣告在創(chuàng)建后會自動拉取廣告。開發(fā)者可以通過 ad-custom 組件的 onload 和 onerror 事件監(jiān)聽廣告拉取成功或失敗。

<view class="adContainer">
  <ad-custom unit-id="xxxx" bindload="adLoad" binderror="adError"></ad-custom>
</view>
Page({
  adLoad() {
    console.log('原生模板廣告加載成功')
  },
  adError(err) {
    console.log('原生模板廣告加載失敗', err)
  }
})

廣告定時刷新

開發(fā)者可以在創(chuàng)建 原生模板 廣告時傳入 ad-intervals 參數(shù)實(shí)現(xiàn)廣告的定時刷新,ad-intervals 參數(shù)為數(shù)字類型,單位為秒。注意:自動刷新的間隔不能低于30秒,因此 ad-intervals 的參數(shù)值必須大于或等于30。

<view class="adContainer">
  <ad-custom unit-id="xxxx" ad-intervals="30"></ad-custom>
</view>


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號