微信小程序添加插屏广告

目录

微信小程序创建项目配置底部导航栏
微信小程序滚动播放内容
微信小程序功能中心模块开发
微信小程序个人中心页面开发
微信小程序获取电话号码
微信小程序显示列表数据
微信小程序显示分页列表
微信小程序添加插屏广告
微信小程序添加激励式广告

最终效果可扫码查看
可查看效果二维码
遇到问题可通过公众号留言反馈
留言扫描二维码

概述

如果小程序用户数大于一千,可以申请流量主,则能够添加广告内容。
插屏广告的微信说明为

// 在页面中定义插屏广告
let interstitialAd = null

// 在页面onLoad回调事件中创建插屏广告实例
if (wx.createInterstitialAd) {
  interstitialAd = wx.createInterstitialAd({
    adUnitId: 'adunit-a4e30ba8401134fb'
  })
  interstitialAd.onLoad(() => {})
  interstitialAd.onError((err) => {})
  interstitialAd.onClose(() => {})
}

// 在适合的场景显示插屏广告
if (interstitialAd) {
  interstitialAd.show().catch((err) => {
    console.error(err)
  })
}

开发

按照微信的说明直接添加三部分代码即可直接实现,但是开发者工具有时候是不显示插屏广告的,需要在真机上查看。
第一部分,直接写到js文件的第一行。
第二部分,写到js文件的onLoad方法中。
第三部分,测试写到了onShow方法中,这样每次进入页面就都会显示广告。

代码使用已经开发好的更多功能页面,在此基础上进行修改。之前的介绍为https://blog.csdn.net/m0_58095675/article/details/121073241

只修改了js文件,其他文件无变化

let interstitialAd = null
Page({
  data: {
    list3:[],
    list4:[],
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: false,
    vertical: true,
    autoplay: true,
    circular: true,
    interval: 2000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0
  },
  onLoad: function () {
    if (wx.createInterstitialAd) {
      interstitialAd = wx.createInterstitialAd({
        adUnitId: 'adunit-a4e30ba8401134fb'
      })
      interstitialAd.onLoad(() => {console.log('插屏 广告加载成功')})
      interstitialAd.onError((err) => {})
      interstitialAd.onClose(() => {console.log('插屏 广告关闭')})
    }

    var that=this;
    wx.request({
      url: 'http://yr.lootaa.com/ship/time/todaySave',
      success (res) { 
        that.setData({
          list3: res.data.data.data
        })
        console.log(res.data.data.data)
      }
    })
    
    wx.request({
      url: 'http://yr.lootaa.com/time/channel/lately',
      success (res) {
        that.setData({
          list4: res.data.data
        })
        console.log(res.data.data)
      }
    })
  },

  onShow:function() {
    if (interstitialAd) {
      interstitialAd.show().catch((err) => {
        console.error(err)
      })
    }
  }

})
  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lootaa

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值