codecamp

百度智能小程序 广告

ad 广告

解释:广告组件,按照流量主开通指引中的操作获取广告组件代码。

属性说明

属性名 类型 默认值 必填 说明
appid String 小程序应用 ID
apid String 小程序广告位 ID
type String feed 广告类型:banner/feed,需和百青藤平台上的代码位类型相匹配。参考下面的 type 有效值
updatetime String 更改该属性,可以触发广告刷新
binderror EventHandle 广告组件加载失败时触发
bindload EventHandle 广告组件加载完成触发
bindclose EventHandle 关闭广告组件时触发
bindstatus EventHandle 贴片类型广告播放期间触发

type 有效值

说明
banner 横幅类型
feed 信息流类型
pre-roll 前贴类型
post-roll 后贴类型

binderror 事件触发

触发时机: 代码执行异常以及状态不符合广告要求

返回参数:

代码 状态 说明
1001-1 内部错误 初始化失败
1001-2 内部错误 广告返回执行异常
1001-3 内部错误 渲染广告异常
1001-4 内部错误 广告异常
1001-5 内部错误 广告缓存异常
1002-1 广告请求 广告返回异常
1003-2 无可用广告 数据层级不对
1003-3 无可用广告 广告内容不完整
1004-1 媒体接入异常 web 化广告不渲染
1004-2 媒体接入异常 视频贴片广告组件放置不在 video 内
1004-3 媒体接入异常 视频贴片当前是非同层渲染

bindstatus 事件触发

触发时机:事件触发在视频贴片的情况下返回参数如下

 statusFunc(e) {
    // e = {status:''}  具体如下
 }
属性 说明
videoend 视频结束, 触发时机:1、如果有广告返回,广告播放结束。2、如果无广告返回
show 广告视频播放中
close 广告播放结束
noAd 无广告返回

示例 

在开发者工具中打开


以下代码仅做示例,需要在百青藤平台申请代码位替换下方 appid 和 apid ,方可正常显示示例效果。

代码示例 1 :横幅类型

<view class="ad-container">
    <ad appid="f71feede"
        apid="7182322"
        type="banner"
        data-update="updatetime1"
        updatetime="{{updatetime1}}"
        binderror="binderror"
        bindload="bindload"
        bindclose="bindclose"
        bindstatus="bindstatus">
    </ad>
</view>
Page({
    bindload(event) {
        console.log(event);
    },
    binderror(event) {
        const update = event.target.dataset.update;
        this.setData(update, `${+new Date()}`);
    },
    bindclose(event) {
        console.log(event);
    }
});
  • 从百青藤获取的代码,是 <ad></ad> 标签组件,把这段代码,嵌入到页面中你需要展现广告的位置处,然后给他一些样式就可以,样式控制只能到 <ad> 这一层,内部的展示效果对小程序的开发者来说没有权限。
  • banner 样式的背景色默认透明,建议开发者自定义背景色。通过(div style="background-color: #fff")自行定义。其中 #fff 代表白色,可以根据广告场景自行修改参数。

代码示例 2 :信息流大图类型

<view class="ad-container">
    <ad appid="f71feede"
        apid="7182323" 
        type="feed"
        data-update="updatetime2"
        updatetime="{{updatetime2}}"
        binderror="binderror"
        bindload="bindload"
        bindclose="bindclose"
        bindstatus="bindstatus">
    </ad>
</view>

代码示例 3 :信息流三图类型

<view class="ad-container">
    <ad appid="f71feede"
        apid="7182347"
        type="feed"
        data-update="updatetime3"
        updatetime="{{updatetime3}}"
        binderror="binderror"
        bindload="bindload"
        bindclose="bindclose"
        bindstatus="bindstatus">
    </ad>
</view>

代码示例 4 :信息流左图类型

<view class="ad-container">
    <ad appid="f71feede"
        apid="7182324"
        type="feed"
        data-update="updatetime4"
        updatetime="{{updatetime4}}"
        binderror="binderror"
        bindload="bindload"
        bindclose="bindclose"
        bindstatus="bindstatus">
    </ad>
</view>

代码示例 5 :信息流右图类型

<view class="ad-container">
    <ad appid="f71feede"
        apid="7182325"
        type="feed"
        data-update="updatetime5"
        updatetime="{{updatetime5}}"
        binderror="binderror"
        bindload="bindload"
        bindclose="bindclose"
        bindstatus="bindstatus">
    </ad>
</view>

代码示例 6 :信息流视频类型

<view class="ad-container">
    <ad appid="f71feede"
        apid="7182334"
        type="feed"
        data-update="updatetime6"
        updatetime="{{updatetime6}}"
        binderror="binderror"
        bindload="bindload"
        bindclose="bindclose"
        bindstatus="bindstatus">
    </ad>
</view>

代码示例 7 :后贴片类型

<view class="ad-container">
    <view class="tip-strong">注:后贴片广告于视频结束后随机自动播放,且仅支持播放一次;广告未出现或再次观看,请退出页面重新进入。</view>
    <video src="https://fcvideo.cdn.bcebos.com/0ee396f19db9337511d1d1340a683e53.mp4">
        <ad appid="f71feede"
            apid="7182330"
            data-update="updatetime7"
            updatetime="{{updatetime7}}"
            type="post-roll"
            binderror="binderror"
            bindload="bindload"
            bindclose="bindclose"
            bindstatus="bindstatus">
        </ad>
    </video>
</view>

代码示例 8 :前贴片类型

<view class="ad-container">
    <view class="tip-strong">注:前贴片广告于视频开始前随机自动播放,且仅支持播放一次;广告未出现或再次观看,请退出页面重新进入。</view>
    <video src="http://miniapp-ad.cdn.bcebos.com/common/video-12.mp4">
        <ad appid="f71feede"
            apid="7183268"
            type="pre-roll"
            data-update="updatetime8"
            updatetime="{{updatetime8}}"
            binderror="binderror"
            bindload="bindload"
            bindclose="bindclose"
            bindstatus="bindstatus">
        </ad>
    </video>
</view>

Bug & Tip

  • Tip:从百青藤获取的代码,是 ad 组件,把这段代码,嵌入到页面中你需要展现广告的位置处,然后给他一些样式就可以,样式控制只能到 ad 这一层,内部的展示效果对小程序的开发者来说没有权限。
  • Tip:banner 样式的背景色默认透明,建议开发者自定义背景色。通过(div style="background-color: #fff")自行定义。其中 #fff 代表白色,可以根据广告场景自行修改参数。
  • Tip:信息流广告可在百青藤平台配置四种样式:大图、多图、左图右文、右图左文。
  • Tip:视频贴片类型基于同层渲染,需 swan-core 版本 3.70.x 版本以上。
  • Tip:视频前贴 ios 11.17 之前广告的视频播放是和媒体公用一个 video,会出现 video 事件多次触发,安卓暂无影响
  • Tip: 视频后贴 暂时和媒体公用一个 video,会出现 video 事件多次触发
  • Tip: 视频贴片广告播放期间切换 video 的 src 变化,都会导致广告中止。


百度智能小程序 画布
百度智能小程序 开放数据
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

百度智能小程序开发文档

百度智能小程序 组件

百度智能小程序 地图

百度智能小程序 画布

百度智能小程序 API

百度智能小程序 界面

百度智能小程序 关注小程序引导组件

百度智能小程序 自定义组件

百度智能小程序 媒体

百度智能小程序 设备

百度智能小程序 拨打电话

百度智能小程序 内存警报

百度智能小程序 手机联系人

百度智能小程序 用户截屏事件

百度智能小程序 第三方平台

百度智能小程序 开放接口

百度智能小程序 百度收银支付

百度智能小程序 分包预下载

百度智能小程序 数据分析

百度智能小程序 服务端

百度智能小程序 云开发

百度智能小程序 初始化

百度智能小程序 云函数

百度智能小程序 服务端初始化

百度智能小程序 服务器获取上下文

百度智能小程序 服务端云函数

百度智能小程序 开发教程

百度智能小程序 功能开发

百度智能小程序 基本原理

百度智能小程序 小程序自动化

百度智能小程序 视频教程

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }