miniapp-tracker-sdk
v0.0.10
Published
npm install @tklc/miniapp-tracker-sdk --registry=http://10.0.0.122:7001
Downloads
5
Readme
install
npm install @tklc/miniapp-tracker-sdk --registry=http://10.0.0.122:7001
app.js
import Tracker from '@tklc/miniapp-tracker-sdk'
App({
onLaunch(options){
Tracker.App.init({
appId:'2019022763399300',// 区别不同小程序,可用小程序自己的appId
server:['http://10.0.0.122:8088/event/upload'],
version:'1.0',//更新小程序请更新此版本
lauchOpts:options,
appName:"苏州小程序",
//bizScenario:‘xxxxx’, 不传入此值会去自动从options取渠道字段
stat_auto_click:true,//自动埋点
mtrDebug:false
},this)
....
}
.....
page:
const app = getApp();
Page({
onLoad() {
app.Tracker.Page.init()
},
userId
app.getUserInfo().then(
user => {
this.setData({
user,
});
app.Tracker.setUserId(user.userId)
},
() => {
// 获取用户信息失败
}
);
API
页面自动埋点
埋点说明
自动点击事件埋点请初始化时设置 stat_auto_click = true
页面加载埋点自动,需每个 page init
onLoad() {
app.Tracker.Page.init()
....
组件里面:
didMount() {
getApp().Tracker.Component.init(this)
....
点击埋点 xml 配置
<view class="service-item" a:for="{{my_service_icon.ele_icons}}" >
<image class="icon-logo" src="{{item.icon_img}}" mode="widthFix"
data-seed="埋点seed名称"
data-group="卡面" data-index="{{index}}"
data-obj="{{item}}"
onTap="handleIconClick"/>
<text class="text">{{item.icon_name}}</text>
</view>
data-obj 里要带 icon_name ,url_path,url_type,url_data,url_remark, 点击事件会传过去
注意事项: 需要配置 data-group(板块) 和 data-index(位置, 有 a:for 的才有) 如 data-group="卡面" data-index="{{index}}"
page js 方法
const app = getApp()
createPage({
....
,
async onLoad() {
app.Tracker.Page.init() //埋点init 每个page都需要,自动埋页面onShow事件
,
handleIconClick(e){
app.handleIconClick(e)
},
....
app.js 统一封装
handleIconClick(e) {
console.log('handleClick', e.currentTarget.dataset)
this.handleNavigate(obj)
},
async handleNavigate(options) { //跳转
....
}
点击事件手动埋点
如 app.Tracker.click('seedName1',{a:1,b:2})
错误日志上送:
app.Tracker.err('tag','error msg')
一般日志上送
app.Tracker.log('test Log')
上送有数值的埋点事件
app.Tracker.calc('seedNameCalc',10)
const app = getApp();
app.Tracker.log('test Log')
app.Tracker.calc('seedNameCalc',10)
app.Tracker.err('tag','error msg')
app.Tracker.click('seedName1',{a:1,b:2})
app.Tracker.setUserId(user)