# point_plugin **Repository Path**: liming436_admin/point_plugin ## Basic Information - **Project Name**: point_plugin - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-11-05 - **Last Updated**: 2025-03-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # point_plugin > 小程序数据埋点 ## 说明 ``` bash # 插件说明 这个插件是目前用于uniapp/mpvue的数据埋点使用的 ``` ``` bash # 安装 npm i point_plugin ``` ## 使用 * ### 初始化注册 * 在项目根目录App.js入口文件的onLaunch生命周期中里调用**this.getwxObj_()** 方法 分别传入uni(也可以是wx) appVersion param api 并且在App.js 的 onshow 生命周期里塞入需要打点的页面并调用打点方法 ``` onLaunch() { this.getwxObj_({ root:uni, //root是小程序根对象 入参可以是uni 也可以是 wx appVersion:'1.2.1', //当前小程序版本号 param:{}, //接口需要额外加入的参数 api:this.pointUpload, //埋点上传的方法 success:function(res){ //初始化成功回调 console.log(res) } }) }, methods:{ pointUpload(data){ //自己自定义封装的埋点上传方法 console.log(data) 这个是埋点回调的数据 下面可以写自己上传的接口代码 uni.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data, //上传给后台的data对象 注:如果需要额外加入自定义的参数可以在this.getwxObj_的param里加入 header: { 'content-type': 'application/json' // 默认值 }, success (res) { console.log(res) } }) } }, onShow: function() { this.getRoute_([ //这个是加入的需要埋点的页面 'pages/index/index', 'pages/goods/index/index' ]) this.$$startPoint() //这个方法是统计小程序启动(包括冷启动丶热启动)的埋点 }, ``` * ### 事件埋点 * 如果需要事件埋点比如点击事件,直接调用**this.$$eventPoint({desc:{}})** 示例埋点如下: ``` methods:{ //需要打点页面的methods click(){ this.$$eventPoint({desc:{label:'点击购买按钮':value:'1'}}) //自定义埋点规则 支持desc内部键值对自定义 } } ```