更新记录
1.2.0(2024-08-02) 下载此版本
免费开放
1.0.0(2024-07-28) 下载此版本
1.0.0
平台兼容性
uni-app
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 | 
|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | √ | - | - | - | - | - | 
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 | 
|---|---|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | √ | - | √ | √ | √ | √ | 
其他
| 多语言 | 暗黑模式 | 宽屏模式 | 
|---|---|---|
| × | × | √ | 
SCPoint 埋点
日常开发过程中可能遇到统计页面中的元素被用户看到了多少次、点击了多少次的需求,也就是曝光埋点、点击埋点,通过SCPoint组件可以轻松实现,开发人员只需要传入埋点ID、内容、监听事件即可,无需关心监听逻辑。该组件融合了点击、曝光事件回调,可以满足开发需求,具体使用请查看API文档
设计特色
SCPoint组件是基于IntersectionObserver API实现,可以实现对页面元素的监听,当元素进入/离开页面时,触发对应事件,有关该API的详细使用可查看MDN文档。
- 曝光原理使用的是intersectionRatio参数,当元素与页面视窗有重叠就算未完全展示也判断为曝光;
 - 该组件支持同时监听多个元素;
 - 埋点内状态独立,互不影响;
 
简单使用
定义一个简单的曝光埋点,并在曝光埋点事件内打印埋点内容和事件参数,打开控制台查看效果。
<template>
        <view  class="content">
            <view  class="text-area">
            <text  class="title">{{title}}</text>
            </view>
            <view  class="content-middle"></view>
            <xhy-scpoint  id="showMore1" reportContent="上报内容1"@onPointShow="onPointShow">
                <button  type="primary">曝光埋点1</button>
            </xhy-scpoint>
        </view>
</template>
<script>
export  default {
    data() {
        return {
            title:  'Hello'
        }
    },
    onLoad() {
    },
    methods: {
        onPointShow(info) {
            console.log(info);
        }
    }
}
</script>
<style>
    .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    }
    .logo {
    height: 200rpx;
    width: 200rpx;
    margin-top: 200rpx;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 50rpx;
    }
    .text-area {
    display: flex;
    justify-content: center;
    }
    .title {
    font-size: 36rpx;
    color: #8f8f94;
    }
    .content-middle {
    height: 800px;
    width: 100%;
    }
    button {
    margin-bottom: 20px;
    }
</style>
曝光点击混合埋点
如果需要同时监听曝光和点击事件,可以使用onPointShow和onPointClick属性,打开控制台查看效果。
<template>
        <view  class="content">
            <view  class="text-area">
            <text  class="title">{{title}}</text>
            </view>
            <view  class="content-middle"></view>
            <xhy-scpoint  id="showMore1" reportContent="上报内容1"@onPointShow="onPointShow" @onPointClick="onPointShow">
                <button  type="primary">曝光埋点1</button>
            </xhy-scpoint>
        </view>
</template>
<script>
export  default {
    data() {
        return {
            title:  'Hello'
        }
    },
    onLoad() {
    },
    methods: {
        onPointShow(info) {
            console.log(info);
        }
    }
}
</script>
<style>
    .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    }
    .logo {
    height: 200rpx;
    width: 200rpx;
    margin-top: 200rpx;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 50rpx;
    }
    .text-area {
    display: flex;
    justify-content: center;
    }
    .title {
    font-size: 36rpx;
    color: #8f8f94;
    }
    .content-middle {
    height: 800px;
    width: 100%;
    }
    button {
    margin-bottom: 20px;
    }
</style>
单次页面访问重复触发曝光事件
埋点内容出现在视窗内会触发曝光事件,如果设置reportAllways为true,当埋点消失后再次出现也会触发曝光事件,打开控制台查看效果。
<template>
        <view  class="content">
            <view  class="text-area">
            <text  class="title">{{title}}</text>
            </view>
            <view  class="content-middle"></view>
            <xhy-scpoint  id="showMore1" reportContent="上报内容1"@onPointShow="onPointShow" @onPointClick="onPointShow" :reportAllways="true">
                <button  type="primary">曝光埋点1</button>
            </xhy-scpoint>
        </view>
</template>
<script>
export  default {
    data() {
        return {
            title:  'Hello'
        }
    },
    onLoad() {
    },
    methods: {
        onPointShow(info) {
            console.log(info);
        }
    }
}
</script>
<style>
    .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    }
    .logo {
    height: 200rpx;
    width: 200rpx;
    margin-top: 200rpx;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 50rpx;
    }
    .text-area {
    display: flex;
    justify-content: center;
    }
    .title {
    font-size: 36rpx;
    color: #8f8f94;
    }
    .content-middle {
    height: 800px;
    width: 100%;
    }
    button {
    margin-bottom: 20px;
    }
</style>
参数配置
| 属性名 | 描述 | 类型 | 默认值 | 
|---|---|---|---|
| id | 埋点id,必须保障id唯一,且符合变量命名规范 | string | 
(必填) | 
| reportContent | 埋点需要上报的内容 | string | 
(必填) | 
| reportAllways | 单次页面访问是否重复触发曝光事件 | boolean | false | 
| onPointShow | 埋点曝光回调事件 | (value: Object) => void | 无 | 
| onPointClick | 埋点点击回调事件 | (value: Object) => void | 无 | 

                                                                    
                                                                        收藏人数:
                                    
                                                        下载插件并导入HBuilderX
                                                    
                                            下载示例项目ZIP
                                        
                                        赞赏(0)
                                    
                                            
 下载 813
                
 赞赏 1
                
            
                    下载 10692317 
                
                        赞赏 1797 
                    
            
            
            
            
            
            
            
            
            
            
            
            
            
            
                        
                                赞赏
                            
            
京公网安备:11010802035340号