james-sensor
v0.0.8
Published
james-sensor
Downloads
12
Readme
项目
james-sensor
项目本地开发
项目本身使用: rollupV2 工具库打出的 esm 包
1. 项目初始化
npm install
2. 库暴露出来的方法
创建并初始化
/*
__DEV__: 是否是开发环境
options: 用于覆盖默认配置
*/
const createAndInitSA = (__DEV__ = true, options = {})
用户登录
const login = (id) => {
// 默认情况下,是把 cookie_id 作为 Distinct ID 的
sensors.login(id)
}
设置用户属性
const setProfile = (params) => {
sensors.setProfile(params)
}
设置事件静态公共属性
const registerPage = (params) => {
sensors.registerPage(params)
}
手动埋点方法
const track = (name, params) => {
sensors.track(name, params)
}
为React项目的使用导出了方法:
SensorContext
SensorProvider
为Vue2项目的使用导出了方法:
provide
inject
4. sensorsdata.es6.min.js 从哪里来?
github上搜索sa-sdk-javascript
5. 项目打包
npm run build
6. 发布 npm 包
npm run patch
npm login
npm publish
npm 包使用
下载包:
nexus -------- https://nexus.eeo-inc.com/repository/eeo-npm/
nrm use nexus
npm i -D james-sensor
React项目使用:
入口文件:
import { SensorProvider } from 'james-sensor'
<SensorProvider __DEV__={true} options={{ show_log: true }}>
<App />
</SensorProvider>
hooks文件:
import { useContext } from 'react'
import { SensorContext } from 'james-sensor'
export const useSensor = () => {
const { track } = useContext(SensorContext)
// 埋点
const sensor = function (eventName, name) {
track(eventName, {
tab_name: name,
})
}
return {
sensor,
}
}
Vue2项目使用:
入口文件:
import { createAndInitSA, provide } from 'james-sensor'
new Vue({
beforeCreate(){
createAndInitSA()
},
provide
})
打点文件:
import { inject } from 'james-sensor'
export default {
inject,
methods: {
sensors(card) {
track("HelpCenter", {
tab_name: card.tabName
});
},
}
}
神策数据文档地址
注意
1. 使用.npmrc配置registry之后就不需要切换镜像源发布npm包了
2. 注意package.json中的main字段和files字段