集成
目前 Web/小程序 逐步演变为插件化的架构方式。“一切都是插件” 的概念会越发的明显。
在使用插件前,请务必参考 插件使用方式
ES Module 集成方式
import exposure from '/dist/web/plugin/exposure/index.es6';
sensors.use(exposure, {
area_rate: 0,
stay_duration: 2,
repeated: true
});
版本要求
Web SDK v1.23.5及以上版本
使用
在使用神策曝光功能之前,建议先了解下神策曝光的相关介绍:曝光采集
曝光条件配置参数
SDK 提供初始化时,来设置曝光条件,具体参数说明如下:
参数 | 类型 | 默认 | 描述 |
---|---|---|---|
area_rate | Number | 0 | 曝光的可见比例,有效值范围 0~1,
|
stay_duration | Number | 0 | 有效停留时长,单位为秒
|
repeated | Boolean | true | 是否允许采集重复曝光
|
曝光条件设置
初始化设置曝光配置
sensors.use(exposure, {
area_rate: 0,
stay_duration: 2,
repeated: true
});
配置参数:
- area_rate:曝光比例。默认:0,值域:0~1。类型:Number
- stay_duration: 有效曝光停留时长。 默认:0。类型:Number
- repeated: 重复曝光。 默认:true。类型:Boolean
注意:
- 初始化设置的配置,是修改全局的默认配置。
- 标记视图元素时,如果不传入配置项,则会使用全局曝光配置
- 标记视图元素时,如果传入配置项,则会使用传入的自定义配置
曝光元素标记
通过元素配置单独添加曝光参数
除了通过初始化参数配置全局曝光事件采集逻辑,还可以通过设置 HTML 属性针对指定元素进行曝光事件采集配置。
<div data-sensors-exposure-event-name="home_top_banner" data-sensors-exposure-config-area_rate="1" data-sensors-exposure-config-stay_duration="2" data-sensors-exposure-config-repeated="true" data-sensors-exposure-property-propA="valueA" data-sensors-exposure-property-propB="valueB"></div>
配置参数
- data-sensors-exposure-event-name 设置曝光事件名称 (必须设置)
- data-sensors-exposure-config-area_rate 设置曝光比例
- data-sensors-exposure-config-stay_duration 设置有效曝光停留时长
- data-sensors-exposure-config-repeated 设置重复曝光
- data-sensors-exposure-property-* 设置该元素曝光事件自定义属性。属性值为 String。无法是其他类型。
通过 API 配置曝光参数
exposure.addExposureView(document.getElementById('exposure_ele'), {
eventName:'exposure_ele',
config: {
area_rate: 0.5,
stay_duration: 0,
repeated: true
},
properties: {
d: 'abc',
e: false
}
})
配置参数:
element
:曝光元素。类型:HTMLElement- option:
- config: 该次注册曝光标记的配置
- area_rate: 曝光比例。默认:0,值域:0~1。类型:Number
- stay_duration: 有效曝光停留时长。 默认:0。类型:Number
- repeated: 重复曝光。 默认:true。类型:Boolean
properties:
自定义属性。类型:Object。同 track 自定义属性
- config: 该次注册曝光标记的配置
通过 API 删除曝光监听
exposure.removeExposureView(document.getElementById('exposure_ele'))
配置参数:
element
:曝光元素。类型:HTMLElement
注意
- 插件和 SDK 必须在同一个版本中,请勿混合不同版本的 SDK 和插件进行使用。